1.3.1 • Published 6 years ago

simple-countdown v1.3.1

Weekly downloads
10
License
MIT
Repository
-
Last release
6 years ago

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:

KeyShorthand
yearsy
monthsM
weeksw
daysd
hoursh
minutesm
secondss
millisecondsms
new Timer({minutes: 3, seconds: 30}) || new new Timer({m: 3, s: 30})
1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.0.0

7 years ago