simple-countdown

1.3.1 • Public • Published

simple-countdown

This is a simple countdown timer that emits events.

Get started

npm install

Usage

const Timer = require('simple-countdown')
 
const timer = new Timer({minutes: 5})
 
timer.formattedDuration // '00:05:00'
 
timer.on('start', function (evt) {
  // timer has started
})
 
timer.on('tick', function (evt) {
  /* evt is an object like this
    {
      duration: 300000,
      current: 292000,
      formatted: '00:04:29',
      percentage: 3
    }
  */
})
 
timer.on('finish', function (evt) {
  /* evt is an object like this
    {
      duration: 300000,
      current: 0,
      formatted: '00:05:00',
      percentage: 100
    }
  */  
})
 
// when you are ready start the timer
timer.start()

You can use the moment.duration api to create your intervals:

Key Shorthand
years y
months M
weeks w
days d
hours h
minutes m
seconds s
milliseconds ms
new Timer({minutes: 3, seconds: 30}) || new new Timer({m: 3, s: 30})

Readme

Keywords

none

Package Sidebar

Install

npm i simple-countdown

Weekly Downloads

2

Version

1.3.1

License

MIT

Unpacked Size

8.74 kB

Total Files

5

Last publish

Collaborators

  • bmordan