mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-03-28 17:42:40 +01:00
15 lines
351 B
TypeScript
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('');
|
|
};
|