util: stringToUnicodeEntities func

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-06-18 10:07:40 +02:00
parent 3162c096bd
commit e26a82d0aa
2 changed files with 33 additions and 0 deletions

View File

@@ -179,4 +179,10 @@ export class Util {
const bytes = crypto.randomBytes(Math.ceil(length / 2));
return bytes.toString('hex').slice(0, length);
}
public static stringToUnicodeEntities(str: string) {
return Array.from(str)
.map(char => `&#x${char.charCodeAt(0).toString(16)};`)
.join('');
}
}