17 lines
468 B
TypeScript
17 lines
468 B
TypeScript
export default function genRndStr(length?: number, symbols?: boolean) {
|
|
let characters =
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
if (symbols) characters += "-_[]()@";
|
|
|
|
let result = "";
|
|
|
|
const finalLength = length || 12;
|
|
|
|
for (let i = 0; i < finalLength; i++) {
|
|
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
result += characters.charAt(randomIndex);
|
|
}
|
|
|
|
return result;
|
|
}
|