Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Created May 17, 2021 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfoxall/4b3653e3816d11f2113bb8a8dfad2bdb to your computer and use it in GitHub Desktop.
Save benfoxall/4b3653e3816d11f2113bb8a8dfad2bdb to your computer and use it in GitHub Desktop.
Function for parsing emoji sequences
//
// https://unicode.org/Public/emoji/13.0/emoji-sequences.txt
export function* emojiList(sequences) {
const LINES = /^[0-9A-F\.\ ]*;/mg;
const TRAILER = /\W+;$/;
const RANGE = /(.*)\.\.(.*)/;
for (const line of sequences.match(LINES)) {
const code = line.replace(TRAILER, '');
const range = code.match(RANGE)
if (range) {
let a = parseInt(range[1], 16);
const b = parseInt(range[2], 16);
for (; a <= b; a++) yield [a]
} else {
yield code.split(' ').map(p => parseInt(p, 16))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment