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

cli-simple-progress

v2.0.0

Published

Simple to use progress-bar for command-line/terminal applications

Downloads

67

Readme

cli-simple-progress

npm package

Simple to use progress-bar for command-line/terminal applications

NPM version NPM Downloads

Installation

$ npm install cli-simple-progress

Usage

increase(value[, tokens])

const bar = new ProgressBar({
  width: 30,
  template: `CLI Progress | ${chalk.green('{complete}')}${chalk.white('{incomplete}')} | {percent}% | {current}/{total}`,
  complete: '\u2588',
  incomplete: '\u2591'
});

const timer = setInterval(() => {
  bar.increase(Math.round(Math.random() * 10));
}, 50);
bar.on('complete', () => {
  clearInterval(timer);
});

progress(decimal[, tokens])

const bar = new ProgressBar({
  width: 30,
  template: 'CLI Progress | {complete}{incomplete} | {percent}% | {current}/{total}',
  complete: '=',
  incomplete: '-'
});

const timer = setInterval(() => {
  bar.progress(Math.random() / 2);
}, 50);
bar.on('complete', () => {
  clearInterval(timer);
});

ratio(decimal[, tokens])

const bar = new ProgressBar({
  width: 30,
  template: 'CLI Progress | {complete}{incomplete} | {percent}% | {current}/{total}Mb/s Chunks | Speed: {speed}Mb/s',
  complete: '\u2588',
  incomplete: '\u2591'
});

bar.render(0, {
  speed: 'N/A',
  current: 0,
  total: 0
});

const req = request('https://examples/download');

req.on('progress', (state) => {
  bar.ratio(state.percent, {
    total: (state.size.total / 1048576).toFixed(2),
    current: (state.size.transferred / 1048576).toFixed(2),
    speed: (state.speed / 1048576).toFixed(2)
  });
});

update(value[, tokens])

const bar = new ProgressBar({
  width: 30,
  template: `CLI Progress | ${chalk.bgGreen('{complete}')}${chalk.bgWhite('{incomplete}')} | {percent}% | {current}/{total}`,
  complete: ' ',
  incomplete: ' '
});

let value = 0;
const timer = setInterval(() => {
  value += Math.round(Math.random() * 10);
  bar.update(value);
}, 50);
bar.on('complete', () => {
  clearInterval(timer);
});

Options

These are keys in the options object you can pass to the progress bar along with total as seen in the example above.

  • current - current completed value defaulting to 0
  • total - total number of ticks to complete defaulting to 100
  • width - the displayed width of the progress bar defaulting to 20
  • stream - the output stream defaulting to process.stderr
  • clear - option to clear the bar on completion defaulting to false
  • complete - completion character defaulting to " "
  • incomplete - incomplete character defaulting to " "
  • template - a template string defaulting to `${chalk.bgGreen('{complete}')}${chalk.bgWhite('{incomplete}')} {percent}%`
  • done - option to persist the logged output. Useful if you want to start a new log session below the current one. defaulting to true
  • showCursor - option to show the cursor. Useful if a CLI accepts input from a user. defaulting to false

Tokens

These are tokens you can use in the template of your progress bar.

  • {complete} the complete progress bar
  • {incomplete} the incomplete progress bar
  • {current} current tick number
  • {total} total ticks
  • {percent} completion percentage

Custom Tokens

You can define custom tokens by adding a {'name': value} object parameter to your method (update(), ratio(), increase(), progress(), etc.) calls.

const bar = new ProgressBar(':current: :token1 :token2', { total: 3 })
bar.update(1, {
  'token1': "Hello",
  'token2': "World!"
});

bar.done();

bar.update(3, {
  'token1': "Goodbye",
  'token2': "World!"
});

The above example would result in the output below.

1: Hello World!
3: Goodbye World!

Examples

License

MIT