npm.io
1.0.3 • Published 4 years ago

duck-timer

Licence
MIT
Version
1.0.3
Deps
1
Size
110 kB
Vulns
0
Weekly
0
Stars
3

DuckTimer

Node.js CI npm version Downloads

A helpful timer class for both of browsers and node.js.

Installation

npm install duck-timer

Usage

Stopwatch
import DuckTimer from 'duck-timer';
const timer = new DuckTimer({ interval: 100 }); // interval time: 100ms = 0.1sec.

// start.
timer.onInterval(res => {
  console.log(res.seconds);
}).start();

// stop.
timer.stop();

// reset.
timer.reset();
Countdown
import DuckTimer from 'duck-timer';
const timer = new DuckTimer({ interval: 1000 });

timer.setCountdown(`Dec 25, ${new Date().getFullYear()}`)
  .onInterval(res => console.log(res.remain.seconds))
  .onTimeout(() => console.log('Merry Christmas!!!'))
  .start();

API

Please see DuckTimer API.

License

MIT License

Keywords