16 lines
405 B
TypeScript
16 lines
405 B
TypeScript
|
// generateId :: Integer -> String
|
||
|
export function getRandomString (len: number) {
|
||
|
let crypto = require("crypto");
|
||
|
let id = crypto.randomBytes(len).toString('hex');
|
||
|
return id;
|
||
|
|
||
|
// function dec2hex (dec) {
|
||
|
// return dec.toString(16).padStart(2, "0")
|
||
|
// }
|
||
|
//
|
||
|
//
|
||
|
// var arr = new Uint8Array((len || 40) / 2)
|
||
|
// window.crypto.getRandomValues(arr)
|
||
|
// return Array.from(arr, dec2hex).join('')
|
||
|
}
|