Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nanospinner

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanospinner - npm Package Compare versions

Comparing version 0.1.14 to 0.1.15

46

index.d.ts
interface Options {
stream?: NodeJS.WriteStream
interval?: number
frames?: string[]
}
interface SpinnerOptions {
text?: string
mark?: string
}
interface Spinner {
text: string
frames: string[]
interval: number
reset(): Spinner
spin(): Spinner
stop(opts: SpinnerOptions): Spinner
start(): Spinner
error(opts: SpinnerOptions): Spinner
success(opts: SpinnerOptions): Spinner
}
export function createSpinner(text?: string, opts?: Options): Spinner
text?: string
stream?: NodeJS.WriteStream
interval?: number
frames?: string[]
}
interface SpinnerOptions {
text?: string
mark?: string
}
interface Spinner {
update(opts: Options): Spinner
reset(): Spinner
spin(): Spinner
stop(opts: SpinnerOptions): Spinner
start(): Spinner
error(opts: SpinnerOptions): Spinner
success(opts: SpinnerOptions): Spinner
}
export function createSpinner(text?: string, opts?: Options): Spinner

@@ -5,4 +5,6 @@ let { green, red, yellow } = require('picocolors')

function createSpinner(text = '', opts = {}) {
let { stream = process.stderr } = opts
let current = 0,
interval = opts.interval || 25,
stream = opts.stream || process.stderr,
frames = opts.frames || symbols.frames,
state = 'stopped',

@@ -12,7 +14,2 @@ timer

let spinner = {
text,
isTTY,
frames: opts.frames || symbols.frames,
interval: opts.interval || 25,
reset() {

@@ -33,5 +30,4 @@ current = 0

render() {
let frame = spinner.frames[current]
let str = `${yellow(frame)} ${spinner.text}`
spinner.isTTY && spinner.write(`\x1b[?25l`)
let str = `${yellow(frames[current])} ${text}`
isTTY && spinner.write(`\x1b[?25l`)
spinner.write(str, true)

@@ -42,3 +38,3 @@ },

spinner.render()
current = (current + 1) % spinner.frames.length
current = (current + 1) % frames.length
state = 'spinning'

@@ -48,5 +44,12 @@ return spinner

update(opts = {}) {
opts.text && (text = opts.text)
opts.frames && (frames = opts.frames)
opts.interval && (interval = opts.interval)
return spinner
},
loop() {
spinner.spin()
timer = setTimeout(() => spinner.loop(), spinner.interval)
timer = setTimeout(() => spinner.loop(), interval)
},

@@ -61,8 +64,9 @@

stop(opts = {}) {
let frame = spinner.frames[current]
let { mark = yellow(frame), text = spinner.text } = opts
let mark = opts.mark || yellow(frames[current])
spinner.update({ text: opts.text || text })
spinner.write(`\x1b[2K\x1b[1G`)
spinner.write(`${mark} ${text}\n`)
spinner.isTTY && spinner.write(`\x1b[?25h`)
isTTY && spinner.write(`\x1b[?25h`)
clearTimeout(timer)

@@ -73,7 +77,7 @@ state = 'stopped'

success(opts) {
success(opts = {}) {
return spinner.stop({ ...opts, mark: green(symbols.tick) })
},
error(opts) {
error(opts = {}) {
return spinner.stop({ ...opts, mark: red(symbols.cross) })

@@ -80,0 +84,0 @@ }

{
"name": "nanospinner",
"version": "0.1.14",
"version": "0.1.15",
"description": "Simple and tiny spinner library for Node.js",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc