Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript typings (#4) #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
146 changes: 146 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
declare namespace Spinnies {
type StopAllStatus = 'succeed' | 'fail' | 'stopped';
type SpinnerStatus = StopAllStatus | 'spinning' | 'non-spinnable';

interface Spinner {
interval: number;
frames: string[];
}

interface SpinnerOptions {
/**
* Optional text to show in the spinner. If none is provided, the name field will be shown.
*/
text?: string;

/**
* Optional, indent the spinner with the given number of spaces.
* */
indent?: number;

/**
* Initial status of the spinner. Valid statuses are: succeed, fail, spinning, non-spinnable and stopped.
*/
status?: SpinnerStatus;

/**
* Any valid chalk color.
*/
color?: string;

/**
* Any valid chalk color.
*/
succeedColor?: string;

/**
* Any valid chalk color.
*/
failColor?: string;
}

interface Options {
/**
* Any valid chalk color. The default value is white.
*/
color?: string;

/**
* Any valid chalk color. The default value is green.
*/
succeedColor?: string;

/**
* Any valid chalk color. The default value is red.
*/
failColor?: string;

/**
* Any valid chalk color. The default value is greenBright.
*/
spinnerColor?: string;

/**
* The default value is ✓.
*/
succeedPrefix?: string;

/**
* The default value is ✖.
*/
failPrefix?: string;

/**
* Disable spins (will still print raw messages).
*/
disableSpins?: boolean;

/**
* Spinner configuration
*/
spinner?: Spinner;
}
}

declare class Spinnies {
static dots: Spinnies.Spinner;
static dashes: Spinnies.Spinner;

constructor(options?: Spinnies.Options);

/**
* Add a new spinner with the given name.
*/
add: (
name: string,
options?: Spinnies.SpinnerOptions
) => Spinnies.SpinnerOptions;

/**
* Get spinner by name.
*/
pick: (name: string) => Spinnies.SpinnerOptions;

/**
* Remove spinner with name.
*/
remove: (name: string) => Spinnies.SpinnerOptions;

/**
* Updates the spinner with name name with the provided options.
*/
update: (
name: string,
options?: Spinnies.SpinnerOptions
) => Spinnies.SpinnerOptions;

/**
* Sets the specified spinner status as succeed.
*/
succeed: (
name: string,
options?: Spinnies.SpinnerOptions
) => Spinnies.SpinnerOptions;

/**
* Sets the specified spinner status as fail.
*/
fail: (
name: string,
options?: Spinnies.SpinnerOptions
) => Spinnies.SpinnerOptions;

/**
* Stops the spinners and sets the non-succeeded and non-failed ones to the provided status.
*/
stopAll: (
status?: Spinnies.StopAllStatus
) => { [name: string]: Spinnies.SpinnerOptions };

/**
* @returns false if all spinners have succeeded, failed or have been stopped
*/
hasActiveSpinners: () => boolean;
}

export = Spinnies;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.5.1",
"description": "Create and manage multiple spinners in command-line interface programs",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "npx mocha test"
},
Expand Down