minimal-timer
v4.1.0
Published
Minimal time tracker.
Downloads
48
Maintainers
Readme
minimal-timer
Keeps track of the elapsed time in miliseconds.
Install
$ npm install minimal-timer --save
Usage
const delay = require('delay')
const timer = require('minimal-timer')
const time = timer() // instantiates the timer
time.start()
await delay(500)
console.log(time.elapsedTime()) // => 500 +-
time.stop()
await delay(500)
console.log(time.elapsedTime()) // => 500 +-
time.resume()
await delay(500)
console.log(time.elapsedTime()) // => 1000 +-
API
timer() object
Creates a new instance
start(customStartDate[optional]) void
Starts/Restart the timer
customStartDate Date
[optional]
resume() void
Resumes the timer.
stop() number
Stops the timer
Returns the elapsed time in miliseconds
elapsedTime() number
Returns the elapased between the start time and the current time in miliseconds
isRunning() boolean
Returns true if the timer is running otherwise false
License
MIT © Alvaro Bernal