Skip to content

Commit

Permalink
update github emoji aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
GaZaTu committed Jan 2, 2023
1 parent ca74542 commit ae66f04
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ const fetchEmojiAliasesFromGithub = async () => {
const emojis = []

const emojiAliasesResponse = await fetch(GITHUB_EMOJI_ALIASES_URL, { agent: httpProxyAgent })
const emojiAliasesRegex = /^\s*"([^"]+)": "https:\/\/github\.githubassets\.com\/images\/icons\/emoji\/unicode\/([^.]+)\.png\?v8"/gm
const emojiAliasesTxt = await emojiAliasesResponse.text()
const emojiAliasesJson = /** @type {{ [key: string]: string }} */ (await emojiAliasesResponse.json())

let match
while ((match = emojiAliasesRegex.exec(emojiAliasesTxt)) !== null) {
if (match.index === emojiAliasesRegex.lastIndex) {
emojiAliasesRegex.lastIndex++
for (const [alias, url] of Object.entries(emojiAliasesJson)) {
const match = /unicode\/([\w-]+)\.png/.exec(url)
if (!match) {
continue
}

const codepoints = match[2].split('-')
const codepoints = match[1].split('-')
const filename = `${__dirname}/../src/res/72x72/${codepoints.join('-')}.png`
const emojiStr = String.fromCodePoint(...codepoints.map(c => parseInt(c, 16)))

Expand All @@ -38,7 +37,7 @@ const fetchEmojiAliasesFromGithub = async () => {

if (existsSync(filename)) {
emojis.push({
name: match[1],
name: alias,
str: emojiStr,
charCodes: emojiCharCodes,
})
Expand Down
Loading

0 comments on commit ae66f04

Please sign in to comment.