mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-10 21:50:14 -07:00
Recognize Emojis
This commit is contained in:
@@ -89,4 +89,25 @@ export function ellipsizeEnd(text: string, maxLength: number, maxLines?: number)
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
export function textEscapeHtml(text: string): string {
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
|
||||
export function textIsSingleEmoji(text: string): boolean {
|
||||
if (!Intl.Segmenter)
|
||||
throw new Error('Intl.Segmenter is not supported');
|
||||
|
||||
// create segmenter instance with default locale
|
||||
const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
||||
const segments = Array.from(segmenter.segment(text));
|
||||
return segments.length === 1;
|
||||
}
|
||||
Reference in New Issue
Block a user