Skip to content

Commit 6e7798a

Browse files
committed
Tests
1 parent 3f399dd commit 6e7798a

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ ES2024 added support for matching multicharacter Unicode *properties of strings*
121121

122122
All of this is why the popular *emoji-regex* package exists. It does a great job of accurately matching most common-sense emoji. But to do so, it uses a massive (~13 kB uncompressed) regex that hard codes a list of Unicode code points that are tied to a specific Unicode version. Conversely, *emoji-regex-xs* uses a general pattern that continues to be highly accurate in matching emoji, but uses only ~0.2 kB to do so. It follows *emoji-regex*'s API and reuses its tests, so it can be swapped-in as a replacement.
123123

124-
> **Note:** The Unicode standard includes an [official regex](https://www.unicode.org/reports/tr51/#EBNF_and_Regex) for matching emoji. However, although it can serve as a good foundation (after adapting to the JavaScript regex flavor), it doesn't match underqualified emoji including those in the Unicode standard's emoji-test.txt list.
124+
> **Note:** The Unicode standard includes an [official regex](https://www.unicode.org/reports/tr51/#EBNF_and_Regex) for matching emoji. However, although it can serve as a good foundation (after adapting to the JavaScript regex flavor), it matches some non-emoji characters like digits 0-9 and it matches fragments of some underqualified emoji (including some of those in the Unicode standard's emoji-test.txt list).
125125
126126
<!-- Badges -->
127127

test/tests.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,32 @@ describe('regex', () => {
161161
}
162162
}
163163

164-
it('does not match non-emoji sequences in property Emoji', () => {
165-
['#', '*', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].forEach(char => {
164+
// Test platform-specific emoji sequences
165+
for (const sequence of [
166+
// women wrestling: light skin tone (added to draft Emoji 17.0 in 2025)
167+
'\u{1F93C}\u{1F3FB}\u{200D}\u{2640}\u{FE0F}',
168+
// flag for Texas
169+
'\u{1F3F4}\u{E0075}\u{E0073}\u{E0074}\u{E0078}\u{E007F}',
170+
// ninja cat
171+
'\u{1F431}\u{200D}\u{1F464}',
172+
]) {
173+
test(sequence);
174+
}
175+
176+
it('does not match non-emoji sequences', () => {
177+
for (const char of [
178+
'A', '\u200D', '\u20E3', '\uFE0F',
179+
// Within \p{Emoji}
180+
'#', '*', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
181+
]) {
166182
assert.doesNotMatch(char, regex());
167-
assert.doesNotMatch(`char\uFE0F`, regex());
168-
});
183+
assert.doesNotMatch(`${char}\uFE0F`, regex());
184+
}
185+
});
186+
187+
it('matches adjacent emoji sequences as separate matches', () => {
188+
assert.strictEqual('\u{1F431}\u{1F464}'.match(regex()).length, 2);
189+
assert.strictEqual('🇧🇷🇯🇵🏳️‍🌈🇺🇸'.match(regex()).length, 4);
169190
});
170191

171192
// it('contains no non-ASCII Unicode symbols', () => {

0 commit comments

Comments
 (0)