@augment-vir/browser
Advanced tools
Comparing version 6.1.0 to 6.1.1
export function randomString(inputLength = 16) { | ||
const arrayLength = Math.ceil(inputLength / 2); | ||
// server side | ||
if (typeof window === 'undefined' || !window.crypto) { | ||
throw new Error(`window/window.crypto is not defined for the "${randomString.name}" function. If using this in a Node.js context, import ${randomString.name} from 'augment-vir/node-js' instead`); | ||
if (typeof self === 'undefined' || !self.crypto) { | ||
throw new Error(`self/self.crypto is not defined for the "${randomString.name}" function. If using this in a Node.js context, import ${randomString.name} from 'augment-vir/node-js' instead`); | ||
} | ||
const uintArray = new Uint8Array(arrayLength); | ||
window.crypto.getRandomValues(uintArray); | ||
self.crypto.getRandomValues(uintArray); | ||
return (Array.from(uintArray) | ||
@@ -10,0 +10,0 @@ .map((value) => value.toString(16).padStart(2, '0')) |
{ | ||
"name": "@augment-vir/browser", | ||
"version": "6.1.0", | ||
"version": "6.1.1", | ||
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/browser", | ||
@@ -5,0 +5,0 @@ "bugs": { |
2548
6