Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7c1d9b4

Browse files
authored
Merge pull request #6490 from robintown/regional-indicators
Add regional indicators to emoji picker
2 parents 27d7dae + fef2d40 commit 7c1d9b4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/emoji.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ export const EMOTICON_TO_EMOJI = new Map<string, IEmoji>();
3535

3636
export const getEmojiFromUnicode = unicode => UNICODE_TO_EMOJI.get(stripVariation(unicode));
3737

38+
const isRegionalIndicator = (x: string): boolean => {
39+
// First verify that the string is a single character. We use Array.from
40+
// to make sure we count by characters, not UTF-8 code units.
41+
return Array.from(x).length === 1 &&
42+
// Next verify that the character is within the code point range for
43+
// regional indicators.
44+
// http://unicode.org/charts/PDF/Unicode-6.0/U60-1F100.pdf
45+
x >= '\u{1f1e6}' && x <= '\u{1f1ff}';
46+
};
47+
3848
const EMOJIBASE_GROUP_ID_TO_CATEGORY = [
3949
"people", // smileys
4050
"people", // actually people
@@ -72,7 +82,11 @@ export const EMOJI: IEmoji[] = EMOJIBASE.map((emojiData: Omit<IEmoji, "shortcode
7282
shortcodes: typeof shortcodeData === "string" ? [shortcodeData] : shortcodeData,
7383
};
7484

75-
const categoryId = EMOJIBASE_GROUP_ID_TO_CATEGORY[emoji.group];
85+
// We manually include regional indicators in the symbols group, since
86+
// Emojibase intentionally leaves them uncategorized
87+
const categoryId = EMOJIBASE_GROUP_ID_TO_CATEGORY[emoji.group] ??
88+
(isRegionalIndicator(emoji.unicode) ? "symbols" : null);
89+
7690
if (DATA_BY_CATEGORY.hasOwnProperty(categoryId)) {
7791
DATA_BY_CATEGORY[categoryId].push(emoji);
7892
}

0 commit comments

Comments
 (0)