Measure time difference.
Installation is done using the
npm install
command:
$ npm install time-differ
via ES5:
const timeDiff = require("time-differ");
type Unit =
| "*"
| "all"
| "years"
| "months"
| "weeks"
| "days"
| "hours"
| "minutes"
| "seconds"
| "milliseconds";
Creates a new index point of time, with an option to set the Time Unit.
const timeDiff = require("time-differ");
const point = timeDiff.create("seconds");
Measure the time difference.
const timeDiff = require("time-differ");
let point = timeDiff.create("seconds");
// ..some code goes here (took 40s)
point(); // ⇆ 40s
// ..some code goes here (took 15s)
point("After some code"); // ⇆ 55s (After some code)
point = timeDiff.create("*");
// ..some code goes here
point("An example of all units."); // ⇆ 1m::20s::325ms # An example of all units.
Set the time precision (decimal places).
const timeDiff = require("time-differ");
timeDiff.precision(1);
const point = timeDiff.create("seconds");
// ..some code goes here
point("1 decimal places"); // ⇆ 4.3s # 1 decimal places
timeDiff.precision(4);
// ..some code goes here
point("1 decimal places"); // ⇆ 16.3254s # 4 decimal places
An object that is automatically generated within callback argument.
type TimeObject = {
y?: number;
mn?: number;
w?: number;
d?: number;
h?: number;
m?: number;
s?: number;
ms: number;
};
Use the difference data to create custom scenario.
const timeDiff = require("time-differ");
const point = timeDiff.create("*");
// ..some code goes here # took 15s
point((timeObject) => {
console.log(`It took ${timeObject.mn} months.`); // It took 0 months.
console.log(`It took ${timeObject.s} seconds.`); // It took 7 seconds.
});