* Check if a grapheme cluster (after segmentation) could possibly be an RGI emoji. * This is a fast heuristic to avoid the expensive rgiEmojiRegex test. * The tested Unicode blocks are deliberately broad to account for future * Unicode additions.
(segment: string)
| 25 | * Unicode additions. |
| 26 | */ |
| 27 | function couldBeEmoji(segment: string): boolean { |
| 28 | const cp = segment.codePointAt(0)!; |
| 29 | return ( |
| 30 | (cp >= 0x1f000 && cp <= 0x1fbff) || // Emoji and Pictograph |
| 31 | (cp >= 0x2300 && cp <= 0x23ff) || // Misc technical |
| 32 | (cp >= 0x2600 && cp <= 0x27bf) || // Misc symbols, dingbats |
| 33 | (cp >= 0x2b50 && cp <= 0x2b55) || // Specific stars/circles |
| 34 | segment.includes("\uFE0F") || // Contains VS16 (emoji presentation selector) |
| 35 | segment.length > 2 // Multi-codepoint sequences (ZWJ, skin tones, etc.) |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | // Regexes for character classification (same as string-width library) |
| 40 | const zeroWidthRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Mark}|\p{Surrogate})+$/v; |