Comparing version 3.1.1 to 3.2.0
58
index.js
@@ -9,42 +9,52 @@ 'use strict' | ||
function formatFromMs(value, unit) { | ||
if (!unit || unit === MS) { | ||
return round(value) | ||
} | ||
if (unit === S) { | ||
return round(value / 1e3) | ||
} | ||
return round(value * 1e6) | ||
} | ||
function hirestimeNode() { | ||
const start = process.hrtime() | ||
return unit => { | ||
let elapsed = process.hrtime(start) | ||
let value = elapsed[0] * 1e3 + elapsed[1] / 1e6 | ||
switch (unit) { | ||
case S: | ||
return round(elapsed[0] + elapsed[1] / 1e9) | ||
case NS: | ||
return round(elapsed[0] * 1e9 + elapsed[1]) | ||
} | ||
return round(elapsed[0] * 1e3 + elapsed[1] / 1e6) | ||
return formatFromMs(value, unit); | ||
} | ||
} | ||
function hiresTimeBrowser() { | ||
function hiresTimeBrowserPerformance() { | ||
const start = window.performance.now() | ||
return unit => formatFromMs(window.performance.now() - start, unit) | ||
} | ||
function hiresTimeBrowserDate() { | ||
const start = Date.now() | ||
return unit => formatFromMs(Date.now() - start, unit) | ||
} | ||
return unit => { | ||
var elapsed = Date.now() - start | ||
module.exports = (() => { | ||
if (typeof process != "undefined" && process.hrtime) { | ||
return hirestimeNode | ||
} | ||
switch (unit) { | ||
case S: | ||
return round(elapsed / 1e3) | ||
if (typeof window != "undefined" && window.performance) { | ||
return hiresTimeBrowserDate | ||
} | ||
case NS: | ||
return round(elapsed * 1e6) | ||
} | ||
return hiresTimeBrowserDate | ||
})() | ||
return elapsed | ||
} | ||
} | ||
module.exports.node = hirestimeNode | ||
module.exports.browserDate = hiresTimeBrowserDate | ||
module.exports.hiresTimeBrowserPerformance = hiresTimeBrowserPerformance | ||
module.exports = process.hrtime ? hirestimeNode : hiresTimeBrowser | ||
module.exports.S = S | ||
module.exports.MS = MS | ||
module.exports.NS = NS |
{ | ||
"name": "hirestime", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "thin wrapper around process.hrtime", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha tests" | ||
"test": "mocha test.js" | ||
}, | ||
@@ -33,3 +33,3 @@ "repository": { | ||
"hrtimemock": "^2.0.0", | ||
"mocha": "^3.0.0", | ||
"mocha": "^3.4.0", | ||
"sinon": "^1.17.6" | ||
@@ -36,0 +36,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
# hirestime [![Build Status](https://api.travis-ci.org/seriousManual/hirestime.png)](https://travis-ci.org/seriousmanual/hirestime) | ||
# hirestime [![Build Status](https://api.travis-ci.org/seriousManual/hirestime.png)](https://travis-ci.org/seriousManual/hirestime) | ||
@@ -7,4 +7,4 @@ [![NPM](https://nodei.co/npm/hirestime.png)](https://nodei.co/npm/hirestime/) | ||
`hirestime` is a thin wrapper around `process.hrtime()` that does the clumsy handling of the returned array for you. | ||
Also works in the browser. | ||
`hirestime` is a thin wrapper around the common time measuring APIs (node and the browser). | ||
Uses `process.hrtime()` on node, the [performance API](https://developer.mozilla.org/de/docs/Web/API/Performance/now) in the browser and falls back to `Date` if neither is available. | ||
@@ -27,3 +27,3 @@ ## Installation | ||
* `hirestime.S` elapsed time in seconds | ||
* `hirestime.MS` elapsed time in milliseoncds | ||
* `hirestime.MS` elapsed time in milliseconds | ||
* `hirestime.NS` elapsed time in nanoseconds | ||
@@ -30,0 +30,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9514
147
1