### Install Multispinner Source: https://github.com/codekirei/node-multispinner/blob/master/readme.md Install the multispinner module using npm. This is a prerequisite for using the module in your Node.js project. ```bash $ npm install --save multispinner ``` -------------------------------- ### multispinner.start() Source: https://context7.com/codekirei/node-multispinner/llms.txt Manually starts the spinner animation loop. This is used when `autoStart` is set to `false` during initialization. ```APIDOC ## Method: multispinner.start() ### Description Starts the spinner animation loop. This method should only be called when the `autoStart` option is set to `false`. If `autoStart` is `true` (the default), calling this method will cause spinners to animate at double speed with dropped frames. ### Method `start` ### Endpoint N/A (Instance Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const Multispinner = require('multispinner') // Create spinners with manual start const m = new Multispinner(['task1', 'task2'], { autoStart: false }) // Do some setup work first console.log('Preparing tasks...') // Then start the spinners setTimeout(() => { m.start() // Complete tasks after starting setTimeout(() => m.success('task1'), 1000) setTimeout(() => m.success('task2'), 2000) }, 500) ``` ### Response None (Method modifies internal state) ``` -------------------------------- ### Configure Pre-text Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Example of setting preText to prepend text to the spinner animation. ```js var multispinner = new Multispinner(['foo', 'bar'], { preText: 'Completing' }) /** * First frame of spinners would look like this: * * - Completing foo * - Completing bar */ ``` -------------------------------- ### Start Spinner Animation Manually Source: https://context7.com/codekirei/node-multispinner/llms.txt Initiates the animation loop when autoStart is disabled. ```javascript const Multispinner = require('multispinner') // Create spinners with manual start const m = new Multispinner(['task1', 'task2'], { autoStart: false }) // Do some setup work first console.log('Preparing tasks...') // Then start the spinners setTimeout(() => { m.start() // Complete tasks after starting setTimeout(() => m.success('task1'), 1000) setTimeout(() => m.success('task2'), 2000) }, 500) ``` -------------------------------- ### Initialize Multispinner Instances Source: https://context7.com/codekirei/node-multispinner/llms.txt Demonstrates creating spinners from arrays, objects, and applying custom configuration options. ```javascript const Multispinner = require('multispinner') // Create spinners from an array (string is both ID and text) const spinners = new Multispinner(['task1', 'task2', 'task3']) // Create spinners from an object (key is ID, value is display text) const spinners = new Multispinner({ 'download': 'Downloading files...', 'compile': 'Compiling source code...', 'deploy': 'Deploying to server...' }) // Create spinners with custom options const spinners = new Multispinner(['foo', 'bar', 'baz'], { autoStart: false, // Don't start automatically clear: true, // Clear output when complete frames: ['-', '\\', '|', '/'], // Animation frames indent: 2, // Character indentation interval: 80, // Milliseconds between frames preText: 'Processing', // Text before spinner text postText: '...', // Text after spinner text color: { incomplete: 'blue', // Color while spinning success: 'green', // Color on success error: 'red' // Color on error }, symbol: { success: '✓', // Symbol on success error: '✗' // Symbol on error } }) // Start manually if autoStart is false spinners.start() ``` -------------------------------- ### Configure Multispinner Options Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Pass an options object during initialization to customize behavior like auto-start and clearing output. ```js var multispinner = new Multispinner(['foo', 'bar', 'baz'], { autoStart: false, clear: true ) ``` -------------------------------- ### Initialize Multispinner with Object Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Create a multispinner instance using an object where keys are IDs and values are the display text. ```js var multispinner = new Multispinner({ 'Foo': 'Downloading Foo', 'Bar': 'Transpiling Bar', 'Baz': 'Writing Baz' }) ``` -------------------------------- ### Initialize Multispinner with Array Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Create a multispinner instance using an array of unique strings as spinner IDs. ```js var multispinner = new Multispinner([ 'Foo', 'Bar', 'Baz' ]) ``` -------------------------------- ### Configure Colors Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Customize the colors for different spinner states using chalk-compatible values. ```js { incomplete: 'blue', success: 'green', error: 'red' } ``` ```js var multispinner = new Multispinner(['Foo', 'Bar'], { color: { incomplete: 'yellow' } }) ``` -------------------------------- ### Default Option Values Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Default configurations for various spinner settings. ```js { autoStart: true } ``` ```js { clear: false } ``` ```js { frames: ['-', '\\', '|', '/'] } ``` ```js { indent: 2 } ``` ```js { interval: 80 } ``` ```js { preText: '' } ``` -------------------------------- ### Manage Spinner States with Promises Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Demonstrates updating spinner states based on promise resolution or rejection. ```js /** * NOTES: * - This is es6. * - Only the 'foo' spinner is completed in this code, so 'bar' would continue * spinning indefinitely. Generally, you want to complete all your spinners. * - For a more complete demo, check out the cli-with-promises example in the * examples section. */ // make a promise const fooTask = new Promise((resolve, reject) => { // async stuff to do here }) // instantiate multispinner const multispinner = new Multispinner( ['foo', 'bar'], { preText: 'Downloading' } ) // fulfill the promise fooTask .then((res) => { // complete spinner successfully multispinner.success('foo') // possibly do stuff with res here }) .catch((err) => { // complete spinner with error multispinner.error('foo') // possibly do stuff with err here }) ``` -------------------------------- ### Configure custom animation frames Source: https://context7.com/codekirei/node-multispinner/llms.txt Use the 'frames' option to define custom animation sequences. Frames can be strings of any length. ```javascript const Multispinner = require('multispinner') const figures = require('figures') const spinners = ['task A', 'task B', 'task C'] const opts = { interval: 120, // Slower animation for custom frames preText: 'Completing', frames: [ '[ ]', '[* ]', '[** ]', '[ ** ]', '[ ** ]', '[ ** ]', '[ **]', '[ *]' ], symbol: { success: ' '.repeat(7) + figures.tick // Align checkmark with frame width } } const m = new Multispinner(spinners, opts) // Staggered completion setTimeout(() => m.success('task A'), 1500) setTimeout(() => m.success('task B'), 3000) setTimeout(() => m.success('task C'), 4500) ``` -------------------------------- ### Multispinner Constructor Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Initializes a new Multispinner instance with specified spinners and options. ```APIDOC ## new Multispinner(spinners, options) ### spinners (required) An array or object of spinners to create. Once created, spinners are stored in the `multispinner.spinners` object. **Array** An array of strings. Each string becomes a spinner. Each spinner gets its text and ID from the given string. Because these strings are used as IDs, they must be unique. `multispinner` will `throw` if it finds duplicate strings in its spinner array. ```js var multispinner = new Multispinner([ 'Foo', 'Bar', 'Baz' ]) ``` **Object** Given spinner `key: val`, `val` is the text and `key` is the ID. ```js var multispinner = new Multispinner({ 'Foo': 'Downloading Foo', 'Bar': 'Transpiling Bar', 'Baz': 'Writing Baz' }) ``` ### options (optional) Configurable options object. ```js var multispinner = new Multispinner(['foo', 'bar', 'baz'], { autoStart: false, clear: true ) ``` Each option below is shown with its default value. **autoStart** ```js { autoStart: true } ``` If `true`, automatically start spinners after instantiating the `Multispinner` class. If `false`, remember to start the spinners later with `multispinner.start()`. **clear** ```js { clear: false } ``` If `true`, clear output with `logUpdate.clear()` after all spinners have finished. If `false`, output persists. **frames** ```js { frames: ['-', '\\', '|', '/'] } ``` Array of spinner frames. These are cycled to create the spinner animation. Note that frames needn't only be one character -- see the custom animation example. **indent** ```js { indent: 2 } ``` Number of character widths to indent spinners. **interval** ```js { interval: 80 } ``` Number of milliseconds between animation frames. **preText** ```js { preText: '' } ``` Text to insert before spinner text (but after spinner animation). ```js var multispinner = new Multispinner(['foo', 'bar'], { preText: 'Completing' }) /** * First frame of spinners would look like this: * * - Completing foo * - Completing bar */ ``` **postText** ```js { postText: '' } ``` Text to append after spinner text. **color** ```js { incomplete: 'blue', success: 'green', error: 'red' } ``` Colors used for spinners in each possible state. [Chalk](https://github.com/chalk/chalk) is used for colorization, so any chalk-compatible color values are acceptable. Individual colors can be customized without customizing the whole color object. ```js var multispinner = new Multispinner(['Foo', 'Bar'], { color: { incomplete: 'yellow' } }) ``` **symbol** ```js { success: figures.tick, error: figures.cross } ``` Symbols to use in place of the spinner animation for spinners that have completed. [Figures](https://github.com/sindresorhus/figures) is used by default for some nice unicode symbols, but any strings are acceptable. Like colors, individual symbols can be customized without customizing the entire symbol object. ``` -------------------------------- ### Configure Symbols Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Define custom symbols for success and error states. ```js { success: figures.tick, error: figures.cross } ``` -------------------------------- ### Multispinner Constructor Source: https://context7.com/codekirei/node-multispinner/llms.txt Initializes a new Multispinner instance. Spinners can be provided as an array of strings or an object mapping IDs to display text. Various options can be configured for customization. ```APIDOC ## Constructor: new Multispinner(spinners, options) ### Description Creates a new Multispinner instance with the specified spinners and optional configuration. Spinners can be provided as an array of strings (where each string serves as both the ID and display text) or as an object mapping IDs to display text. By default, spinners start automatically after instantiation. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const Multispinner = require('multispinner') // Create spinners from an array (string is both ID and text) const spinners = new Multispinner(['task1', 'task2', 'task3']) // Create spinners from an object (key is ID, value is display text) const spinners = new Multispinner({ 'download': 'Downloading files...', 'compile': 'Compiling source code...', 'deploy': 'Deploying to server...' }) // Create spinners with custom options const spinners = new Multispinner(['foo', 'bar', 'baz'], { autoStart: false, // Don't start automatically clear: true, // Clear output when complete frames: ['-', '\\', '|', '/'], // Animation frames indent: 2, // Character indentation interval: 80, // Milliseconds between frames preText: 'Processing', // Text before spinner text postText: '...', // Text after spinner text color: { incomplete: 'blue', // Color while spinning success: 'green', // Color on success error: 'red' // Color on error }, symbol: { success: '✓', // Symbol on success error: '✗' // Symbol on error } }) // Start manually if autoStart is false spinners.start() ``` ### Response None (Constructor) ``` -------------------------------- ### Multispinner Methods Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Methods for controlling and updating the state of spinners. ```APIDOC ## multispinner.start() Start the spinners. This is only necessary if the `autoStart` option is manually set to `false`. If `autoStart` is `true` (the default), this `start` method should *not* be called -- it would start the spinners twice, giving the appearance of double speed (and dropped frames)! ## multispinner.success(spinner) Complete a spinner and change its state to `success`. `spinner` is the (string) ID of the spinner to complete. The spinner's symbol and color are updated to indicate the `success` state. ## multispinner.error(spinner) Complete a spinner and change its state to `error`. `spinner` is the (string) ID of the spinner to complete. The spinner's symbol and color are updated to indicate the `error` state. ```js /** * NOTES: * - This is es6. * - Only the 'foo' spinner is completed in this code, so 'bar' would continue * spinning indefinitely. Generally, you want to complete all your spinners. * - For a more complete demo, check out the cli-with-promises example in the * examples section. */ // make a promise const fooTask = new Promise((resolve, reject) => { // async stuff to do here }) // instantiate multispinner const multispinner = new Multispinner( ['foo', 'bar'], { preText: 'Downloading' } ) // fulfill the promise fooTask .then((res) => { // complete spinner successfully multispinner.success('foo') // possibly do stuff with res here }) .catch((err) => { // complete spinner with error multispinner.error('foo') // possibly do stuff with err here }) ``` ``` -------------------------------- ### multispinner.success(spinner) Source: https://context7.com/codekirei/node-multispinner/llms.txt Marks a specific spinner as completed with a success state. The spinner stops animating and displays the success symbol and color. ```APIDOC ## Method: multispinner.success(spinner) ### Description Completes a spinner by changing its state to success. The spinner parameter is the string ID of the spinner to complete. Once called, the spinner stops animating, changes to the success symbol, and updates to the success color. ### Method `success` ### Endpoint N/A (Instance Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const Multispinner = require('multispinner') // Create spinners for parallel async tasks const m = new Multispinner(['upload', 'process', 'notify']) // Simulate async operations completing at different times setTimeout(() => { m.success('upload') // Mark upload as successful console.log('Upload completed!') }, 1000) setTimeout(() => { m.success('process') // Mark processing as successful }, 2000) setTimeout(() => { m.success('notify') // Mark notification as successful }, 3000) ``` ### Response None (Method modifies internal state) ``` -------------------------------- ### Handle completion event Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Triggered when all spinners finish, regardless of their final state. ```js multispinner.on('done', () => { // do something now that the spinners are all done }) ``` -------------------------------- ### Integrate Multispinner with Promises Source: https://context7.com/codekirei/node-multispinner/llms.txt Multispinner can track concurrent asynchronous operations by mapping Promise resolutions and rejections to spinner states. ```javascript const Multispinner = require('multispinner') // Example: Download multiple URLs in parallel function downloadFiles(urls) { const spinners = new Multispinner( urls.reduce((obj, url) => { obj[url] = `Downloading ${url}` return obj }, {}), { preText: '' } ) // Create download promises const downloads = urls.map(url => { return fetch(url) .then(response => { if (response.ok) { spinners.success(url) return response.text() } throw new Error(`HTTP ${response.status}`) }) .catch(err => { spinners.error(url) return { error: err.message, url } }) }) // Wait for all downloads and process results return Promise.all(downloads).then(results => { return new Promise(resolve => { spinners.on('done', () => resolve(results)) }) }) } // Usage downloadFiles([ 'https://api.example.com/data1', 'https://api.example.com/data2', 'https://api.example.com/data3' ]).then(results => { console.log('All downloads completed:', results) }) ``` -------------------------------- ### Complete Spinners with Success Source: https://context7.com/codekirei/node-multispinner/llms.txt Marks a specific spinner as successful, stopping its animation and applying success styling. ```javascript const Multispinner = require('multispinner') // Create spinners for parallel async tasks const m = new Multispinner(['upload', 'process', 'notify']) // Simulate async operations completing at different times setTimeout(() => { m.success('upload') // Mark upload as successful console.log('Upload completed!') }, 1000) setTimeout(() => { m.success('process') // Mark processing as successful }, 2000) setTimeout(() => { m.success('notify') // Mark notification as successful }, 3000) ``` -------------------------------- ### Complete Spinners with Error Source: https://context7.com/codekirei/node-multispinner/llms.txt Marks a specific spinner as failed, stopping its animation and applying error styling. ```javascript const Multispinner = require('multispinner') const m = new Multispinner(['validate', 'save', 'index']) // Simulate a task that fails setTimeout(() => { // Validation failed m.error('validate') }, 500) // Other tasks still complete setTimeout(() => m.success('save'), 1000) setTimeout(() => m.success('index'), 1500) ``` -------------------------------- ### Handle the 'success' event in Multispinner Source: https://context7.com/codekirei/node-multispinner/llms.txt The 'success' event fires only if every spinner completes via the success() method. It will not trigger if any spinner encounters an error. ```javascript const Multispinner = require('multispinner') const m = new Multispinner(['download', 'install', 'configure']) m.on('success', () => { console.log('All tasks completed successfully!') process.exit(0) }) // All tasks succeed setTimeout(() => m.success('download'), 1000) setTimeout(() => m.success('install'), 2000) setTimeout(() => m.success('configure'), 3000) // 'success' event fires after configure completes ``` -------------------------------- ### Handle the 'done' event in Multispinner Source: https://context7.com/codekirei/node-multispinner/llms.txt The 'done' event triggers once after all spinners finish, regardless of whether they ended in success or error states. ```javascript const Multispinner = require('multispinner') const m = new Multispinner(['task1', 'task2', 'task3']) m.on('done', () => { console.log('All spinners have finished!') // Perform cleanup or next steps here }) // Complete spinners (mix of success and error) setTimeout(() => m.success('task1'), 1000) setTimeout(() => m.error('task2'), 1500) setTimeout(() => m.success('task3'), 2000) // 'done' event fires after task3 completes ``` -------------------------------- ### Require Multispinner Source: https://github.com/codekirei/node-multispinner/blob/master/readme.md Require the multispinner module in your Node.js application. This makes the Multispinner class available for use. ```javascript var Multispinner = require('multispinner') ``` -------------------------------- ### multispinner.error(spinner) Source: https://context7.com/codekirei/node-multispinner/llms.txt Marks a specific spinner as completed with an error state. The spinner stops animating and displays the error symbol and color. ```APIDOC ## Method: multispinner.error(spinner) ### Description Completes a spinner by changing its state to error. The spinner parameter is the string ID of the spinner to complete. Once called, the spinner stops animating, changes to the error symbol, and updates to the error color. ### Method `error` ### Endpoint N/A (Instance Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const Multispinner = require('multispinner') const m = new Multispinner(['validate', 'save', 'index']) // Simulate a task that fails setTimeout(() => { // Validation failed m.error('validate') }, 500) // Other tasks still complete setTimeout(() => m.success('save'), 1000) setTimeout(() => m.success('index'), 1500) ``` ### Response None (Method modifies internal state) ``` -------------------------------- ### Spinner Object Structure Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md The internal structure of a spinner object stored within the multispinner instance. ```js // example spinner in spinners object { 'foo': { // unique spinner ID 'state': // incomplete, success, or error 'text': // base spinner text plus preText and postText 'current': // colorized symbol and text (what is drawn on screen) } } ``` -------------------------------- ### Handle the 'err' event in Multispinner Source: https://context7.com/codekirei/node-multispinner/llms.txt The 'err' event triggers for each individual spinner that fails. Note that the event name is 'err' rather than 'error'. ```javascript const Multispinner = require('multispinner') const m = new Multispinner(['foo', 'bar', 'baz', 'qux']) m.on('err', (spinnerID) => { console.log(`Spinner '${spinnerID}' finished with an error`) }) m.on('success', () => { console.log('All completed without errors!') }) // Mix of success and error completions setTimeout(() => m.success('foo'), 1000) setTimeout(() => m.error('bar'), 1500) // triggers 'err' event with 'bar' setTimeout(() => m.success('baz'), 2000) setTimeout(() => m.error('qux'), 2500) // triggers 'err' event with 'qux' // Output: "Spinner 'bar' finished with an error" // Output: "Spinner 'qux' finished with an error" ``` -------------------------------- ### Handle error event Source: https://github.com/codekirei/node-multispinner/blob/master/extras/api.md Triggered when a spinner is completed with an error state. Note that the event name is 'err' to avoid conflict with standard Node.js error handling. ```js multispinner.on('err', (spinner) => { console.log(`spinner ${spinner} had an error`) }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.