tests in typescript
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user