Skip to content

Commit fef2d40

Browse files
committed
Add comments to isRegionalIndicator
Signed-off-by: Robin Townsend <robin@robin.town>
1 parent 4ace235 commit fef2d40

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/emoji.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ 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-
Array.from(x).length === 1 && x >= '\u{1f1e6}' && x <= '\u{1f1ff}';
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+
};
4047

4148
const EMOJIBASE_GROUP_ID_TO_CATEGORY = [
4249
"people", // smileys

0 commit comments

Comments
 (0)