Created
May 17, 2021 20:16
-
-
Save benfoxall/4b3653e3816d11f2113bb8a8dfad2bdb to your computer and use it in GitHub Desktop.
Function for parsing emoji sequences
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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