fix: proper browser env check...

This commit is contained in:
ppe
2022-09-20 14:00:13 +02:00
parent 1d0c1a4688
commit 053ceaf3ea

View File

@@ -1,8 +1,8 @@
/* eslint-disable */ /* eslint-disable */
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
import copy from 'fast-copy'; import copy from 'fast-copy';
import { Buffer } from 'redstone-isomorphic'; import {Buffer} from 'redstone-isomorphic';
import { randomUUID } from 'crypto'; import {randomUUID} from 'crypto';
export const sleep = (ms: number): Promise<void> => { export const sleep = (ms: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
@@ -78,9 +78,11 @@ export function bufToBn(buf: Buffer) {
} }
export function isomorphicRandomUUID() { export function isomorphicRandomUUID() {
if (self.crypto) { if (isBrowser() && self.crypto) {
return self.crypto.randomUUID(); return self.crypto.randomUUID();
} else { } else {
return randomUUID(); return randomUUID();
} }
} }
const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");