Nostradamus Predicting Maelstroms

npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

@georapbox/timer

1.1.2 • Public • Published

npm version Build Status dependencies Status devDependencies Status License: MIT

Timer

Minimal javascript library to create and manage timers

NOTE: Depends on window.requestAnimationFrame. If your environment does not support it, you can polyfill.

Install

$ npm install @georapbox/timer --save

API

new Timer([duration], [callback])

Creates a Timer instance.

Param Type Description
[duration] Number The timer's duration (ms). If left undefined or 0 the timer counts up instead of down.
[callback] function Function to be executed while timer is running. The Timer instance is passed by as parameter.

timer.time() ⇒ Object

Get the remaining and elapsed time.
If no duration is specified during initialization, the remaining time will always be 0.

Kind: instance method of Timer
Returns: Object - An object that contains the remaining and the elapsed time in milliseconds.

timer.start([shouldReset]) ⇒ Timer

Start the timer.
If the timer instance has been already started, the timer will just resume.

Kind: instance method of Timer
Returns: Timer - The Timer instance.

Param Type Description
[shouldReset] Boolean If set to true, the timer will reset to initial specified duration.

timer.stop() ⇒ Timer

Stop/Pause the timer.

Kind: instance method of Timer
Returns: Timer - The Timer instance.

timer.reset([shouldStop]) ⇒ Timer

Resets the timer to initial specified duration.

Kind: instance method of Timer
Returns: Timer - The Timer instance.

Param Type Description
[shouldStop] Boolean If set to true, the timer will be forced to stop; otherwise will reset and continue running.

timer.isRunning() ⇒ Boolean

Check (at any time) if the timer is running or not.

Kind: instance method of Timer
Returns: Boolean - True if the timer is running; otherwise false.

Test

$ npm run test

License

The MIT License (MIT)

install

npm i @georapbox/timer

Downloadsweekly downloads

45

version

1.1.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability