tests in typescript

This commit is contained in:
grimhilt
2023-04-01 22:36:51 +02:00
parent 90dd16ee0d
commit 11ab6a6a21
22 changed files with 1258 additions and 412 deletions

View File

@@ -1,4 +1,4 @@
function transformEmojis(str) {
export function transformEmojis(str :string): string {
if (!str) return str;
// Use a regular expression to match emojis in the string
const regex =
@@ -6,20 +6,14 @@ function transformEmojis(str) {
// Replace each matched emoji with its Unicode code point
const transformedStr = str.replace(regex, (match) => {
return "\\u{" + match.codePointAt(0).toString(16).toUpperCase() + "}";
return "\\u{" + match.codePointAt(0)?.toString(16).toUpperCase() + "}";
});
return transformedStr;
}
function decodeEmojis(text) {
export function decodeEmojis(text: string): string {
const regex = /\\u{([^}]+)}/g;
const decodedText = text.replace(regex, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
return decodedText;
}
module.exports = {
transformEmojis,
decodeEmojis
}