Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
Checks / checks (push) Successful in 2m11s
Trigger cinny-mobile / dispatch (push) Successful in 1s

This commit is contained in:
2026-11-01 04:23:53 +11:00
parent 3cd159a63e
commit a6ad8651b3
605 changed files with 11480 additions and 9125 deletions
+27 -35
View File
@@ -14,13 +14,13 @@ const EMOTICON_MAP: Record<string, string> = {
'=)': '😊',
':]': '😊',
':>': '😊',
// Sad faces
':(': '☹️',
':-(': '☹️',
'=[': '☹️',
':<': '☹️',
// Other emotions
';)': '😉',
';-)': '😉',
@@ -28,8 +28,8 @@ const EMOTICON_MAP: Record<string, string> = {
':-P': '😛',
':p': '😛',
':-p': '😛',
'xD': '😆',
'XD': '😆',
xD: '😆',
XD: '😆',
':|': '😐',
':-|': '😐',
':O': '😮',
@@ -42,21 +42,21 @@ const EMOTICON_MAP: Record<string, string> = {
':-*': '😘',
'<3': '❤️',
'</3': '💔',
// Surprised/Shocked
':0': '😯',
':-0': '😯',
// Cool
'8)': '😎',
'8-)': '😎',
'B)': '😎',
'B-)': '😎',
// Crying
':\'(': '😢',
':\')': '😂',
":'(": '😢',
":')": '😂',
// Neutral
':/': '😕',
':-/': '😕',
@@ -72,22 +72,19 @@ const EMOTICON_MAP: Record<string, string> = {
*/
export function convertEmoticons(text: string): string {
let result = text;
// Sort emoticons by length (longest first) to handle overlapping patterns
// e.g., :-) before :)
const emoticons = Object.keys(EMOTICON_MAP).sort((a, b) => b.length - a.length);
for (const emoticon of emoticons) {
// Escape special regex characters
const escapedEmoticon = emoticon.replace(/[.*+?^${}()|[\]\\<>]/g, '\\$&');
// Match emoticons with optional backslash escape
// Matches either \:) (escaped) or :) (not escaped, and not preceded by backslash)
const regex = new RegExp(
`(^|\\s)(\\\\)?(${escapedEmoticon})(?=\\s|$)`,
'g'
);
const regex = new RegExp(`(^|\\s)(\\\\)?(${escapedEmoticon})(?=\\s|$)`, 'g');
result = result.replace(regex, (match, prefix, backslash, emote) => {
// If backslash is present, remove it but keep the emoticon literal
if (backslash) {
@@ -97,7 +94,7 @@ export function convertEmoticons(text: string): string {
return prefix + EMOTICON_MAP[emoticon];
});
}
return result;
}
@@ -110,26 +107,21 @@ export function convertEmoticons(text: string): string {
*/
export function convertEmoticonsInHtml(html: string): string {
let result = html;
// Sort emoticons by length (longest first) to handle overlapping patterns
const emoticons = Object.keys(EMOTICON_MAP).sort((a, b) => b.length - a.length);
for (const emoticon of emoticons) {
// Convert emoticon to HTML entity version (for < and >)
const htmlEmoticon = emoticon
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
const htmlEmoticon = emoticon.replace(/</g, '&lt;').replace(/>/g, '&gt;');
// Escape special regex characters
const escapedEmoticon = htmlEmoticon.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
// Match emoticons at start of string, after whitespace, or after HTML tags
// With optional backslash escape
const regex = new RegExp(
`(^|\\s|>)(\\\\)?(${escapedEmoticon})(?=\\s|<|$)`,
'g'
);
const regex = new RegExp(`(^|\\s|>)(\\\\)?(${escapedEmoticon})(?=\\s|<|$)`, 'g');
result = result.replace(regex, (match, prefix, backslash, emote) => {
// If backslash is present, remove it but keep the emoticon literal
if (backslash) {
@@ -139,7 +131,7 @@ export function convertEmoticonsInHtml(html: string): string {
return prefix + EMOTICON_MAP[emoticon];
});
}
return result;
}
@@ -150,15 +142,15 @@ export function convertEmoticonsInHtml(html: string): string {
*/
export function containsEmoticons(text: string): boolean {
const emoticons = Object.keys(EMOTICON_MAP);
for (const emoticon of emoticons) {
const escapedEmoticon = emoticon.replace(/[.*+?^${}()|[\]\\<>]/g, '\\$&');
const regex = new RegExp(`(^|\\s)(${escapedEmoticon})(?=\\s|$)`);
if (regex.test(text)) {
return true;
}
}
return false;
}