npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smart-spinner

v1.0.1

Published

Simple cli-spinners wrapper.

Downloads

34

Readme

Smart-Spinner

Simple tool to create smart text spinner.

Helps to provide continous feedback of your application internal status without flooding out console or logs.

Small Gif Demo

Large demo here.

Index

Features

  • Provide continuous visual and colorful feedback thought cli-spinners and chalk.

  • Helps to detect when you run into blocking code (spinning will pause while long processing bloking code takes place).

  • Automatically detects when stdout is not connected to the terminal and just initial message (and updates if any) are shown to avoid flooding unattended operation logs.

  • Also detects if terminal supports unicode and ansi color codes gracefully failing back to textual / uncolorized (respectively) approaches.

  • Accepts message as string or callback function (so you can easlily monitor any variable you want).

  • Returns simple API function that lets you:

    • Modify message anytime (even changing from string to callback and vice-versa) by passing new one.
    • Stop spinner (finalization) by passing boolean value indicating whether the whole process finished correctly or not and, optionally, second parameter with new message update.

For better and easier understanding see example below.

Setup

npm install --save smart-spinner

Usage

Module loading

const spinner = require("smart-spinner");

Spinner Creation

var progress = spinner.create(<message> [, <spinner_list>]);

Where:

  • <message>: Message string or callback to generate it. If callback is used, then it is called with single boolean argument indicating if output is actually connected to terminal or not. So complex calculations can be avoided if needed (also callback will be called single time in this case).

  • <spinner_list>: Array of spinner names (See list() or demo() to know which ones are available) or string "all" to use all.

    • Specified spinners will be rotated regularly.
    • If "all" keyword is specified instead, all available ones will be used.
    • If "demo" keyword is specified instead, it will operate just like if demo() were used instead.
    • If string (distinct of "all" and "demo" is used) it wil be threated as single spinner list.

Return value: Callback to control spinner:

Syntax:

  • progress (String <newMsg>): Set message to provided string or callback.
  • progress (Boolean <stop>): Stop spinning with success (stop = true) or failed (stop = false).
  • progress (Boolean <stop>, String <newMsg>) Stop spinning but also updates message.

Other functions

demo()

var progress = spinner.demo([<message>]);

Works like spinner.create() but rotate over all available spinners also showing its name when called without parameters.

In fact it is just a wrapper over create() forcing "demo" keyword as spinner list.

list()

var progress = spinner.list();

Simply shows list of available spinners (More info about them at cli-spinners).

Simple example

const spinner = require("smart-spinner");

var progress = spinner.create("Here is my Spinner");

setTimeout(()=>{
    progress("Now text is updated");
}, 2000);


setTimeout(()=>{
    progress(function(){
        var someStatus = (new Date()).toLocaleString();
        return "Current time: " + someStatus;
    });
}, 4000);


setTimeout(()=>{
    progress("I will finish just in a few seconds more.");
}, 6000);


// Finally: This random timeouts will race to impose its status.  Even not good
// pattern to trigger both success and fail status this example shows how, if it
// happens, the last will be silently ignored.
setTimeout(()=>{
    progress(true, "Success!!");
    // This will replace spinner icon with green check mark and set message to
    // "Success!!".
}, 7000 + Math.random()*3000);

setTimeout(()=>{
    progress(false, "Failed!!");
    // This will replace spinner icon with red cross mark and set message to
    // "Failed!!".
}, 7000 + Math.random()*3000);

See more examples in the examples directory of the project repository.

Contributing

If you are interested in contributing with this project, you can do it in many ways:

  • Creating and/or mantainig documentation.

  • Implementing new features or improving code implementation.

  • Reporting bugs and/or fixing it.

  • Sending me any other feedback.

  • Whatever you like...

Please, contact-me, open issues or send pull-requests thought this project GIT repository