Skip to content

Commit bb71e4e

Browse files
committed
fix: fix browser support
closes #171 Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
1 parent 88fab00 commit bb71e4e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { emptyFunction, tTable } from './constants';
22
import type { Fn, Statistics } from './types';
33

4+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
5+
const isBrowser = !!(globalThis as any).navigator;
6+
47
/**
58
* Converts nanoseconds to milliseconds.
69
*
@@ -17,7 +20,14 @@ export const nToMs = (ns: number) => ns / 1e6;
1720
*/
1821
export const mToNs = (ms: number) => ms * 1e6;
1922

20-
const hrtimeBigint = process.hrtime.bigint.bind(process.hrtime);
23+
let hrtimeBigint: () => bigint;
24+
if (isBrowser) {
25+
hrtimeBigint = () => {
26+
throw new Error('hrtime.bigint() is not supported in this JS environment');
27+
};
28+
} else {
29+
hrtimeBigint = process.hrtime.bigint.bind(process.hrtime);
30+
}
2131
export const hrtimeNow = () => nToMs(Number(hrtimeBigint()));
2232

2333
const performanceNow = performance.now.bind(performance);

0 commit comments

Comments
 (0)