timer-stopwatch
A stopwatch and countdown clock module for node.js
Install
npm install timer-stopwatch
How to
The Gist
new Stopwatch([countDownMS], [options]);
Basic timers
var Stopwatch = require("timer-stopwatch");
var timer = new Stopwatch(60000);
var stopwatch = new Stopwatch();
Event Methods
timer.onTime(function(time) {
console.log(time.ms);
console.log(time.seconds);
});
timer.onDone(function() {
console.log("Timer is complete");
});
timer.onAlmostDone(function() {
console.log("Timer is almost complete");
});
timer
.onTime(cb)
.onAlmostDone(cb)
.onDone(cb);
Timer Methods
timer.start();
timer.stop();
timer.startstop();
timer.reset(countDownMS);
Properties
timer.ms;
timer.seconds;
Options
var options = {
refreshRateMS: 10,
almostDoneMS: 10000
};
var timer = new Stopwatch(60000, options);
Breaking Changes in v0.2
- The
forcestop
event is being depreciated in favour of 'stop'. - Use the
onTime
, onAlmostDone
, onDone
and onStop
methods in favour of .on('eventname')
.
Testing
Unit and Integration tests (requires dev dependencies)
npm test
Thanks to
@MickCrozier - The maintainer of the original package.
Other contributors:
- @danhere
- @connorjburton
- @RafaelKaczmarczyk
- @nitzo
License
MIT License