16 lines
No EOL
375 B
JavaScript
16 lines
No EOL
375 B
JavaScript
// IMPURE
|
|
export const genUUID = (len=16) => {
|
|
const arr = crypto.getRandomValues(new Uint8Array(len));
|
|
let result = "";
|
|
for (let i=0; i<len; i++) {
|
|
const unsignedByte = arr[i];
|
|
if (unsignedByte < 16) {
|
|
result += '0' + unsignedByte.toString(16);
|
|
} else {
|
|
result += unsignedByte.toString(16);
|
|
}
|
|
}
|
|
return result;
|
|
};
|
|
|
|
console.log(genUUID()) |