util: generateRandomString func

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-04-26 13:54:45 +02:00
parent a459c7c911
commit 62e3923775
2 changed files with 21 additions and 0 deletions

View File

@@ -174,4 +174,9 @@ export class Util {
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
public static generateRandomString(length = 10) {
const bytes = crypto.randomBytes(Math.ceil(length / 2));
return bytes.toString('hex').slice(0, length);
}
}