Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ spinner.succeed("All done !");

## API

<details><summary>constructor(options?: ISpinnerOptions)</summary>
<details><summary>constructor(options?: SpinnerOptions)</summary>
<br>

Create a new Spinner. The **options** payload is described by the following TypeScript interface:

```ts
export interface ISpinnerOptions {
export interface SpinnerOptions {
/**
* Spinner name (from cli-spinners lib)
*
Expand Down Expand Up @@ -114,14 +114,14 @@ new Spinner({ name: "dots2" });

</details>

<details><summary>start(text?: string, options?: IStartOptions): Spinner</summary>
<details><summary>start(text?: string, options?: StartOptions): Spinner</summary>

Start the spinner and optionaly write the text passed as first parameter.

The **options** payload is described by the following TypeScript interface:

```ts
export interface IStartOptions {
export interface StartOptions {
withPrefix?: string;
}
```
Expand Down
8 changes: 4 additions & 4 deletions src/Spinner.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const kLogSymbols = process.platform !== "win32" || process.env.CI || process.en
{ success: styleText("green", "✔"), error: styleText("red", "✖") } :
{ success: styleText("green", "√"), error: styleText("red", "×") };

export interface ISpinnerOptions {
export interface SpinnerOptions {
/**
* Spinner name (from cli-spinners lib)
*
Expand All @@ -48,7 +48,7 @@ export interface ISpinnerOptions {
verbose?: boolean;
}

export interface IStartOptions {
export interface StartOptions {
withPrefix?: string;
}

Expand All @@ -71,7 +71,7 @@ export class Spinner extends EventEmitter {
#spinnerPos = 0;
#startTime: number;

constructor(options: ISpinnerOptions = {}) {
constructor(options: SpinnerOptions = {}) {
super();
this.#verbose = options.verbose ?? true;
if (!this.#verbose) {
Expand Down Expand Up @@ -169,7 +169,7 @@ export class Spinner extends EventEmitter {
readline.moveCursor(this.stream, -(stringLength(line)), moveCursorPos);
}

start(text?: string, options: IStartOptions = {}) {
start(text?: string, options: StartOptions = {}) {
this.#started = true;
this.text = text;
if (typeof options.withPrefix === "string") {
Expand Down
12 changes: 6 additions & 6 deletions src/computeWithSpinner.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// Import Internal Dependencies
import {
Spinner,
type ISpinnerOptions
type SpinnerOptions
} from "./Spinner.class.js";

// CONSTANTS
// eslint-disable-next-line func-style
const kDefaultSafeLogger = () => undefined;

export interface IComputeSpinnerOptions {
export interface ComputeSpinnerOptions {
text: string;
spinner?: Omit<ISpinnerOptions, "verbose">;
spinner?: Omit<SpinnerOptions, "verbose">;
withPrefix?: string;
}

export interface ISpinnerLoggerOptions {
export interface SpinnerLoggerOptions {
success?: (elapsedTime: number) => string;
fail?: (error: Error) => string;
}

export async function computeWithSpinner<T = void>(
asynchronousOp: (spinner: Spinner) => Promise<T>,
options: IComputeSpinnerOptions,
logs: ISpinnerLoggerOptions = {}
options: ComputeSpinnerOptions,
logs: SpinnerLoggerOptions = {}
): Promise<T> {
const { success = kDefaultSafeLogger, fail = kDefaultSafeLogger } = logs;
const spinner = new Spinner(options.spinner)
Expand Down