akkoma-fe/tools/sort_emojis.js
yan d5b078e084 Reorder Unicode emojis
Reorder Unicode emojis according to Unicode CLDR emoji collation rules.
2023-02-01 18:09:17 +02:00

27 lines
827 B
JavaScript

const fs = require('fs')
const emojiFilename = '../static/emoji.json'
const data = fs.readFileSync(emojiFilename, 'utf8')
const currentEmojis = JSON.parse(data)
const currentEmojisArray = Object.entries(currentEmojis).map(([name, codepoint]) => {
return {
keyword: name,
value: codepoint
}
}).filter(e => {
const hasSingleCodepoint = Array.from(e.value).length === 1;
const isSkinToneIndicator = e.value.codePointAt(0) >= 0x1F3FB && e.value.codePointAt(0) <= 0x1F3FF;
return !(hasSingleCodepoint && isSkinToneIndicator)
})
const collator = new Intl.Collator('en-u-co-emoji')
currentEmojisArray.sort((a, b) => {
return collator.compare(a.value, b.value)
})
fs.writeFile(emojiFilename, JSON.stringify(currentEmojisArray, null, 2), 'utf8', (err) => {
if (err) console.log('Error writing file', err)
})