UNPKG

@grafana/faro-core

Version:
19 lines 709 B
const alphabet = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789'; export function genShortID(length = 10) { const values = new Uint32Array(length); const cryptoObj = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined; if (cryptoObj === null || cryptoObj === void 0 ? void 0 : cryptoObj.getRandomValues) { cryptoObj.getRandomValues(values); } else { for (let i = 0; i < length; i++) { values[i] = Math.floor(Math.random() * 0x100000000); } } let result = ''; for (let i = 0; i < length; i++) { result += alphabet[values[i] % alphabet.length]; } return result; } //# sourceMappingURL=shortId.js.map