Skip to content

asvorz/time-differ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

time-differ logo


Measure time difference.

NPM Version NPM Downloads

Installation

Installation is done using the npm install command:

$ npm install time-differ

Declaration

via ES5:

const timeDiff = require("time-differ");

Usage

Time Unit

type Unit =
  | "*"
  | "all"
  | "years"
  | "months"
  | "weeks"
  | "days"
  | "hours"
  | "minutes"
  | "seconds"
  | "milliseconds";

Create an Index Point

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");

Time Difference

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.

Time Precision

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

Time Object

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;
};

Custom Time Difference

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.
});

Author

Liav Barsheshet, LBDevelopments

License

MIT

Releases

No releases published

Packages

No packages published