Just a stopwatch-like timer class
Stopwatch is a simple stopwatch-like timer that can emit events. It currently works only in seconds and will parse a string for seconds, minutes, and hours, and fractions thereof.
// Nodevar Stopwatch = require'stopwatch-emitter'Stopwatch;var stopwatch1 = '5m';var stopwatch2 = '30s';// Browservar Stopwatch = '0.5h';
var stopwatch = '5m';// Startstopwatchstart;// Stopstopwatchstop;// Pausestopwatchpause;// Restart from any spotstopwatchrestart;
Stopwatch implements a classic event emitter. The node version uses the node event emitter and the browser version uses Oliver Caldwell's implementation of EventEmitter (thanks!). All events have the same name as the method that invokes them. An additional event
tick is also available which, as you might imagine, is called every second the stopwatch ticks.
var stopwatch = '5m';stopwatchon'start'console.log'Started!';;stopwatchon'pause'console.log'Paused!';;stopwatchstart; // Started!stopwatchpause; // Paused!stopwatchon'tick'console.log'Tick!';;stopwatchrestart;// Tick!// Tick!
Stopwatch also have a few getters for time remaining, current time, and the max time, all in seconds. It also has an isRunning() call.
var stopwatch = '60s';stopwatchgetCurrentTime; // 0stopwatchgetMaxTime; // 60// Start and wait 20 seconds...stopwatchstartstopwatchgetRemainingTime; // 40stopwatchisRunning; // true