Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 25, 2024
0 parents commit abe4ad8
Show file tree
Hide file tree
Showing 13 changed files with 838 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 22
- 20
- 18
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
13 changes: 13 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import yoctoSpinner from './index.js';

const spinner = yoctoSpinner({
text: 'Loading unicorns\n (And rainbows)',
}).start();

setTimeout(() => {
spinner.text = 'Calculating splines';
}, 2000);

setTimeout(() => {
spinner.success('Finished!');
}, 5000);
153 changes: 153 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import {type Writable} from 'node:stream';

export type SpinnerStyle = {
readonly interval?: number;
readonly frames: string[];
};

export type Color =
| 'black'
| 'red'
| 'green'
| 'yellow'
| 'blue'
| 'magenta'
| 'cyan'
| 'white'
| 'gray';

export type Options = {
/**
Text to display next to the spinner.
@default ''
*/
readonly text?: string;

/**
Customize the spinner animation with a custom set of frames and interval.
```
{
frames: ['-', '\\', '|', '/'],
interval: 100,
}
```
Pass in any spinner from [`cli-spinners`](https://github.com/sindresorhus/cli-spinners).
*/
readonly spinner?: SpinnerStyle;

/**
The color of the spinner.
@default 'cyan'
*/
readonly color?: Color;

/**
The stream to which the spinner is written.
@default process.stderr
*/
readonly stream?: Writable;
};

export type Spinner = {
/**
Change the text displayed next to the spinner.
@example
```
spinner.text = 'New text';
```
*/
text: string;

/**
Change the spinner color.
*/
color: Color;

/**
Starts the spinner.
Optionally, updates the text.
@param text - The text to display next to the spinner.
@returns The spinner instance.
*/
start(text?: string): Spinner;

/**
Stops the spinner.
Optionally displays a final message.
@param finalText - The final text to display after stopping the spinner.
@returns The spinner instance.
*/
stop(finalText?: string): Spinner;

/**
Stops the spinner and displays a success symbol with the message.
@param text - The success message to display.
@returns The spinner instance.
*/
success(text?: string): Spinner;

/**
Stops the spinner and displays an error symbol with the message.
@param text - The error message to display.
@returns The spinner instance.
*/
error(text?: string): Spinner;

/**
Stops the spinner and displays a warning symbol with the message.
@param text - The warning message to display.
@returns The spinner instance.
*/
warning(text?: string): Spinner;

/**
Stops the spinner and displays an info symbol with the message.
@param text - The info message to display.
@returns The spinner instance.
*/
info(text?: string): Spinner;

/**
Clears the spinner.
@returns The spinner instance.
*/
clear(): Spinner;

/**
Returns whether the spinner is currently spinning.
*/
get isSpinning(): boolean;
};

/**
Creates a new spinner instance.
@returns A new spinner instance.
@example
```
import yoctoSpinner from 'yocto-spinner';
const spinner = yoctoSpinner({text: 'Loading…'}).start();
setTimeout(() => {
spinner.success('Success!');
}, 2000);
```
*/
export default function yoctoSpinner(options?: Options): Spinner;
Loading

0 comments on commit abe4ad8

Please sign in to comment.