Files
vscode-front-matter/src/utils/encodeEmoji.ts
2023-03-20 13:19:32 +01:00

15 lines
351 B
TypeScript

export const encodeEmoji = (text: string) => {
if (!text || !/\p{Extended_Pictographic}/u.test(text)) {
return text;
}
const characters = [...text].map((el) => {
if (/\p{Extended_Pictographic}/u.test(el)) {
return `\\u${el.codePointAt(0)?.toString(16).toUpperCase()}`;
}
return el;
});
return characters.join('');
};