timerize
A timy timer package to time things !
Installation
npm i timerize
Usage
const Timer = require('timerize').default;
import Timer from 'timerize';
const timer = new Timer;
console.log(timer.elapsed);
timer.format = "s";
console.log(timer.elapsed);
Timer.default_format = "s";
timer.pause();
timer.start();
Important note:
The timer does not consume any resource when it is "running".
Calculations are made when you get the elapsed time.
You can leave him without call pause()
and waiting for it became garbage-collected.
Reference
@@constructor
You can provide two optional arguments: time (starting time, default Date.now()
) and format (default Timer.default_format
).
Timer automatically starts after instanciation, you do not need to call .start()
!
const timer = new Timer(Date.now(), "s");
elapsed
Get elapsed time according to desired format
const elapsed_time = timer.elapsed;
format
Change the elapsed time format output.
Default format is ms
.
Accepted formats are ms
, s
, m
, h
and d
, for milliseconds, seconds, minutes, hours and days.
timer.format = "m";
You can also change defaut format for new instances (and instances that does not have a specified format) with Timer.default_format
Timer.default_format = "s";
pause()
Pause the timer.
You can optionnaly specify a number of milliseconds of how much time the timer should restart automatically.
If the timer is already paused, it will have no action.
timer.pause(ms?);
start()
Start the timer after a pause.
If the timer was not paused, it will be reset.
timer.start();
paused
Check if the timer is paused.
if (timer.paused) {
}