Nano Spinner
Simple and tiny spinner library for Node.js
- It takes 40 times less space in node_modules than
ora
. - It is 7 times faster than
mico-spinner
.
import { createSpinner } from 'nanospinner'
let spinner = createSpinner('Run test')
spinner.start()
setTimeout(() => {
spinner.success()
}, 1000)
Benchmarks
The space in node_modules
including sub-dependencies:
$ ./test/size.js
Data from packagephobia.com
ora 597 kB
cli-spinners 28 kB
mico-spinner 28 kB
nanospinner 13 kB
Library loading time:
$ ./test/loading.js
mico-spinner 15.451 ms
nanospinner 1.551 ms
API
spin()
Looping over spin
method will animate a given spinner.
setInterval(() => {
spinner.spin()
}, 25)
start(opts?)
In order to start the spinner call start
. This will perform drawing the spinning animation
spinner.start()
spinner.start({ text: 'Start' })
stop(opts?)
In order to stop the spinner call stop
. This will finish drawing the spinning animation and return to new line.
spinner.stop()
spinner.stop({ text: 'Done!', mark: ':O' })
success(opts?)
Use success
call to stop the spinning animation and replace the spinning symbol with check mark character to indicate successful completion.
spinner.success()
spinner.success({ text: 'Successful!', mark: ':)' })
error(opts?)
Use error
call to stop the spinning animation and replace the spinning symbol with cross character to indicate error completion.
spinner.error()
spinner.error({ text: 'Error!', mark: ':(' })
update(opts?)
Use update
call to dynamically change
spinner.update({
text: 'Run test',
stream: stream.stdout,
frames: ['.', 'o', '0', '@', '*'],
interval: 100
})
reset()
In order to reset the spinner to its initial frame do:
spinner.reset()
Roadmap
- Multi spinners