12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- const oldEmojiFilename = '../static/emoji.json'
- const newEmojiFilename = 'emojis.json'
- const outputFilename = 'output.json'
- const run = () => {
- const fs = require('fs')
- let newEmojisObject = {}
- let emojisObject = {}
- let data = fs.readFileSync(newEmojiFilename, 'utf8')
-
- const newEmojis = JSON.parse(data).emojis.filter(e => e.emoji.length <= 2)
-
- newEmojis.forEach(e => {
- const name = e.shortname.slice(1, e.shortname.length - 1).toLowerCase()
- if (name.length > 0) {
- newEmojisObject[name] = e.emoji
- }
- })
- data = fs.readFileSync(oldEmojiFilename, 'utf8')
- emojisObject = JSON.parse(data)
-
- Object.keys(emojisObject).forEach(e => {
- if (emojisObject[e].length > 2) emojisObject[e] = undefined
- })
-
- Object.keys(newEmojisObject).forEach(e => {
- if (!emojisObject[e] && newEmojisObject[e].length <= 2) {
- emojisObject[e] = newEmojisObject[e]
- }
- })
-
- const sorted = Object.keys(emojisObject).sort().reduce((acc, key) => {
- if (key.length === 0) return acc
- acc[key] = emojisObject[key]
- return acc
- }, {})
- fs.writeFile(outputFilename, JSON.stringify(sorted, null, 2), 'utf8', (err) => {
- if (err) console.log('Error writing file', err)
- })
- }
- run()
|