Skip to content

AlvaroBernalG/minimal-timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minimal-timer

Keeps track of the elapsed time in miliseconds.

Build Status npm version JavaScript Style Guide

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