Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -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, '<')
|
||||
.replace(/>/g, '>');
|
||||
|
||||
const htmlEmoticon = emoticon.replace(/</g, '<').replace(/>/g, '>');
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user