Skip to content

Commit

Permalink
refactor: type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky committed Apr 30, 2020
1 parent 3826550 commit 62d8fc9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/hrtime.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="node" />
declare const _default: NodeJS.HRTime;
export default _default;
declare let hrtime: {
(previousTimestamp?: [number, number]): number[];
bigint(time?: [number, number]): bigint;
};
export default hrtime;
13 changes: 7 additions & 6 deletions lib/index.es.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var hrtime = function (previousTimestamp) {
var _hrtime = function (previousTimestamp) {
var baseNow = Math.floor((Date.now() - performance.now()) * 1e-3);
var clocktime = performance.now() * 1e-3;
var seconds = Math.floor(clocktime) + baseNow;
Expand All @@ -14,16 +14,17 @@ var hrtime = function (previousTimestamp) {
return [seconds, nanoseconds];
};
var NS_PER_SEC = 1e9;
hrtime.bigint = function (time) {
var diff = hrtime(time);
_hrtime.bigint = function (time) {
var diff = _hrtime(time);
return (diff[0] * NS_PER_SEC + diff[1]);
};
if (typeof process === 'undefined') {
window.process = {};
}
var hrtime = _hrtime;
if (typeof process.hrtime === 'undefined') {
window.process.hrtime = hrtime;
hrtime = window.process.hrtime = _hrtime;
}
var index = process.hrtime;
var hrtime$1 = hrtime;

export default index;
export default hrtime$1;
13 changes: 7 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(global = global || self, global.hrtime = factory());
}(this, (function () { 'use strict';

var hrtime = function (previousTimestamp) {
var _hrtime = function (previousTimestamp) {
var baseNow = Math.floor((Date.now() - performance.now()) * 1e-3);
var clocktime = performance.now() * 1e-3;
var seconds = Math.floor(clocktime) + baseNow;
Expand All @@ -20,18 +20,19 @@
return [seconds, nanoseconds];
};
var NS_PER_SEC = 1e9;
hrtime.bigint = function (time) {
var diff = hrtime(time);
_hrtime.bigint = function (time) {
var diff = _hrtime(time);
return (diff[0] * NS_PER_SEC + diff[1]);
};
if (typeof process === 'undefined') {
window.process = {};
}
var hrtime = _hrtime;
if (typeof process.hrtime === 'undefined') {
window.process.hrtime = hrtime;
hrtime = window.process.hrtime = _hrtime;
}
var index = process.hrtime;
var hrtime$1 = hrtime;

return index;
return hrtime$1;

})));
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const hrtime = (previousTimestamp?: [number, number]) => {
const _hrtime = (previousTimestamp?: [number, number]) => {
const baseNow = Math.floor((Date.now() - performance.now()) * 1e-3);
let clocktime = performance.now() * 1e-3;
let seconds = Math.floor(clocktime) + baseNow;
Expand All @@ -15,14 +15,15 @@ const hrtime = (previousTimestamp?: [number, number]) => {
return [seconds, nanoseconds];
};
const NS_PER_SEC: number = 1e9;
hrtime.bigint = (time?: [number, number]) => {
const diff = hrtime(time);
_hrtime.bigint = (time?: [number, number]) => {
const diff = _hrtime(time);
return ((diff[0] * NS_PER_SEC + diff[1]) as unknown) as bigint;
};
if (typeof process === 'undefined') {
window.process = <any>{};
}
let hrtime = _hrtime;
if (typeof process.hrtime === 'undefined') {
window.process.hrtime = <any>hrtime;
hrtime = window.process.hrtime = <any>_hrtime;
}
export default process.hrtime;
export default hrtime;

0 comments on commit 62d8fc9

Please sign in to comment.