Code Monkey home page Code Monkey logo

nyan-progress's Introduction

nyan-progress

A nyan cat progress bar for Node. npm version

NPM

screenshot


Installation

yarn add nyan-progress

or if you use npm instead,

npm install --save nyan-progress

Usage

import nyanProgress from 'nyan-progress';
// OR
// const nyanProgress = require('nyan-progress);

const progress = nyanProgress(); // initialize
progress.start({ total: 100 }); // start the progress

const timer = setInterval(() => {
  progress.tick();

  if (progress.isComplete) {
    clearInterval(timer);
  }
}, 100);

The above example will produce the result shown in the gif in the begining.

options

The start() function can pass in an option object, the available options are listed below.

  • curr: the start point of the progress. Default: 0.
  • total: the end point of the progress. Default: 100.
  • width: the length of the progress bar. Default: 20.
  • renderThrottle: the interval that the progress update, in milliseconds. Default: 500.
  • message: an object containing the message to show in the progress.
    • downloading: a list of frames to show when downloading. Default: ['Nyaning. ', 'Nyaning.. ', 'Nyaning...'].
    • finished: a string to show when the progress is completed. Default: 'Nyaned'.
    • error: a string to show when the progress is interupted. Default: 'Something nyan wrong...'.
  • callback: callback function to do when completed.

You can also pass the callback function as second argument of the start() function.

progress.start({}, callback);

The start() function also return a promise.

progress.start().then(callback);

API

start(options, callback?)

The function to nyan the cat.

tick(value? = 1)

The function that increment curr by value, value is default to 1 if not specified. When curr reached to total, the progress will stop.

interupt()

For whatever reason you want to interupt the nyaning, call it. Note that it would not throw any error but display error message in the progress itself.

License

MIT

Credits

nyan-progress's People

Contributors

kevin940726 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

maja-lin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.