Lightweight and efficient spinner package optimized exclusively for Bun (ESM-only)
npm install nspin-bunstyleText and performance.now()) along with Bun's native capabilities to deliver an ultra-fast, minimal CLI spinner experience—all without external dependencies.
styleText and performance.now().
start, updateText, updateFrames, and stop.
updateFrames(newFrames: string[]).
bash
bun add nspin-bun
`
> Note: Although available on npm, nspin-bun is optimized specifically for Bun environments.
Quick Usage
Below is a basic example that demonstrates how to initialize a spinner, update its status, and stop it when the task is complete.
`typescript
import { Spinner } from "nspin-bun";
// Define spinner frames (e.g., progressive updates)
const spinner = new Spinner({
frames: ["⠋", "⠙", "⠹", "⠸"],
interval: 80,
format: "green"
});
spinner.start("Initializing...");
let progress = 0;
const interval = setInterval(() => {
progress += 20;
spinner.updateText(Progress: ${progress}%);
if (progress >= 100) {
clearInterval(interval);
spinner.stop("Task complete!");
}
}, 1000);
`
API Overview
- new Spinner(options)
Create a new spinner instance with the following options:
- frames: An array of spinner frames (e.g., ["⠋", "⠙", "⠹", "⠸"]).
- interval: Frame delay in milliseconds (default is 80).
- format: Styling options applied via styleText.
- position: Position relative to the text ('left' or 'right').
- Instance Methods:
- start(text?: string): Begin the spinner with an optional initial message.
- updateText(newText: string): Update the spinner’s displayed message in real time.
- updateFrames(newFrames: string[]): Dynamically update the spinner frames.
- stop(finalText?: string)`: Stop the spinner and optionally show a final message.