ff-operation-server/src/helpers/stringHelper.ts
Julian Krauser 1d56c7f798 base structure
transfered from ff admin
2025-02-16 10:48:12 +01:00

17 lines
574 B
TypeScript

import crypto from "crypto";
export abstract class StringHelper {
static random(len: number, charSet?: string): string {
// charSet = charSet || "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// var randomString = "";
// for (var i = 0; i < len; i++) {
// var randomPoz = Math.floor(Math.random() * charSet.length);
// randomString += charSet.substring(randomPoz, randomPoz + 1);
// }
// return randomString;
return crypto
.randomBytes(len)
.toString("base64")
.replace(/[^a-zA-Z0-9]/g, "");
}
}