Skip to content

marinko-peso/tiny-timer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiny-timer npm dependencies license

Small countdown timer and stopwatch module.

install

npm install tiny-timer

example

const Timer = require('tiny-timer')

let timer = new Timer()

timer.on('tick', (ms) => console.log('tick', ms))
timer.on('done', () => console.log('done!'))

timer.start(5000) // run for 5 seconds

usage

timer = new Timer([{ interval: 1000, stopwatch: false }])

Optionally set the refresh interval in ms, or stopwatch mode instead of countdown.

timer.start(duration [, interval]) {

Starts timer running for a duration specified in ms. Optionally overide the default refresh interval in ms.

timer.stop()

Stops timer.

timer.pause()

Pauses timer.

timer.resume()

Resumes timer.

events

timer.on('tick', (ms) => {})

Event emitted every interval with the current time in ms.

timer.on('done', () => {})

Event emitted when the timer reaches the duration set by calling timer.start().

properties

timer.time

Gets the current time in ms.

timer.duration

Gets the total duration the timer is running for in ms.

timer.status

Gets the current status of the timer as a string: running, paused or stopped.

About

🕑 Small countdown timer and stopwatch module.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%