fix: proper browser env check...
This commit is contained in:
@@ -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;}");
|
||||||
|
|||||||
Reference in New Issue
Block a user