2022-11-16 15:25:46 +00:00
|
|
|
// Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
|
|
function escapeRegExp(string:string) {
|
|
|
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function replaceAll(inputString:string, toReplace:string, toReplaceWith:string) {
|
|
|
|
return inputString.replace(`/:${escapeRegExp(toReplace)}:/g`, toReplaceWith);
|
2022-11-17 00:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
import { randomBytes } from "crypto";
|
|
|
|
|
|
|
|
export function generateSession() : Promise<string> {
|
|
|
|
return new Promise<string>((resolve, reject) => {
|
|
|
|
randomBytes(12, (err, buf) => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve(buf.toString("hex"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function generateSessionSync() : string {
|
|
|
|
return randomBytes(12).toString("hex");
|
2022-11-16 15:25:46 +00:00
|
|
|
}
|