Comparing version 5.0.6 to 6.0.0
@@ -1,7 +0,3 @@ | ||
export declare const S = "s"; | ||
export declare const MS = "ms"; | ||
export declare const NS = "ns"; | ||
declare type unit = 's' | 'ms' | 'ns'; | ||
export declare function hirestimeNode(): { | ||
(unit?: unit): number; | ||
(): number; | ||
s: () => number; | ||
@@ -15,3 +11,3 @@ seconds(): number; | ||
export declare function hiresTimeBrowserPerformance(): { | ||
(unit?: unit): number; | ||
(): number; | ||
s: () => number; | ||
@@ -25,3 +21,3 @@ seconds(): number; | ||
export declare function hiresTimeBrowserDate(): { | ||
(unit?: unit): number; | ||
(): number; | ||
s: () => number; | ||
@@ -28,0 +24,0 @@ seconds(): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.S = 's'; | ||
exports.MS = 'ms'; | ||
exports.NS = 'ns'; | ||
let DEP_WARNING = false; | ||
const round = (number) => Math.round(number * 100) / 100; | ||
function formatFromMs(value, unit = exports.MS) { | ||
if (unit === exports.MS) { | ||
return round(value); | ||
} | ||
if (unit === exports.S) { | ||
return round(value / 1e3); | ||
} | ||
return round(value * 1e6); | ||
} | ||
function getElapsor(getTime) { | ||
const ret = (unit = undefined) => { | ||
if (unit && !DEP_WARNING) { | ||
console.log('hirestime: please note that specifying a unit is deprecated and will be removed in the future, use the named methods instead'); | ||
DEP_WARNING = true; | ||
} | ||
return formatFromMs(getTime(), unit); | ||
}; | ||
ret.s = ret.seconds = () => formatFromMs(getTime(), exports.S); | ||
ret.ms = ret.milliseconds = () => formatFromMs(getTime(), exports.MS); | ||
ret.ns = ret.nanoseconds = () => formatFromMs(getTime(), exports.NS); | ||
const ret = () => round(getTime()); | ||
ret.s = ret.seconds = () => round(getTime() / 1e3); | ||
ret.ms = ret.milliseconds = () => round(getTime()); | ||
ret.ns = ret.nanoseconds = () => round(getTime() * 1e6); | ||
return ret; | ||
@@ -29,0 +10,0 @@ } |
{ | ||
"name": "hirestime", | ||
"version": "5.0.6", | ||
"version": "6.0.0", | ||
"description": "thin wrapper around process.hrtime", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -15,13 +15,5 @@ # hirestime [](https://travis-ci.org/seriousManual/hirestime) | ||
### returnedFunction([unit]) | ||
### returnedFunction() | ||
Returns the elapsed time since the call of `hirestime` in milliseconds. | ||
An optional unit parameter can be specified that will modify the unit in which the elapsed time will be calculated. | ||
Using the parameter is deprecated though, instead you should use the namend methods to specify the recalculation unit. | ||
#### Possible Parameters (deprecated) | ||
* `hirestime.S` elapsed time in seconds | ||
* `hirestime.MS` elapsed time in milliseconds | ||
* `hirestime.NS` elapsed time in nanoseconds | ||
## Examples | ||
@@ -28,0 +20,0 @@ |
6806
110
53