New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

time-differ

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

time-differ

Measure time difference.

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

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

Keywords

time

FAQs

Package last updated on 21 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts