@grafana/faro-core
Version:
Core package of Faro.
22 lines • 812 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.genShortID = genShortID;
const alphabet = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789';
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