2016-07-07 17:35:22 +00:00
|
|
|
|
var fs = require('fs'),
|
|
|
|
|
emojiData = require('emoji-data'),
|
|
|
|
|
inflection = require('inflection'),
|
|
|
|
|
mkdirp = require('mkdirp')
|
2016-05-31 14:36:52 +00:00
|
|
|
|
|
2016-07-07 17:35:22 +00:00
|
|
|
|
var categories = ['People', 'Nature', 'Foods', 'Activity', 'Places', 'Objects', 'Symbols', 'Flags'],
|
|
|
|
|
data = { categories: [], emojis: {}, skins: {} },
|
|
|
|
|
categoriesIndex = {}
|
2016-05-31 14:36:52 +00:00
|
|
|
|
|
|
|
|
|
categories.forEach((category, i) => {
|
|
|
|
|
data.categories[i] = { name: category, emojis: [] }
|
|
|
|
|
categoriesIndex[category] = i
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
emojiData.sort((a, b) => {
|
2016-07-07 17:35:22 +00:00
|
|
|
|
var aTest = a.sort_order || a.short_name,
|
|
|
|
|
bTest = b.sort_order || b.short_name
|
2016-05-31 14:36:52 +00:00
|
|
|
|
|
|
|
|
|
return aTest - bTest
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
emojiData.forEach((datum) => {
|
|
|
|
|
var category = datum.category,
|
|
|
|
|
shortName = datum.short_name,
|
|
|
|
|
categoryIndex
|
|
|
|
|
|
2016-05-31 20:42:22 +00:00
|
|
|
|
if (!datum.category) {
|
2016-05-31 14:36:52 +00:00
|
|
|
|
throw new Error('“' + datum.short_name + '” doesn’t have a category')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
datum.name || (datum.name = datum.short_name.replace(/\-/g, ' '))
|
|
|
|
|
datum.name = inflection.titleize(datum.name || '')
|
|
|
|
|
|
2016-07-07 17:33:12 +00:00
|
|
|
|
if (datum.category == 'Flags') {
|
|
|
|
|
datum.name = datum.name.replace(/\s(\w+)$/, (letters) => letters.toUpperCase())
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
|
if (!datum.name) {
|
|
|
|
|
throw new Error('“' + datum.short_name + '” doesn’t have a name')
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 21:22:40 +00:00
|
|
|
|
datum.emoticons = datum.texts || []
|
|
|
|
|
if (datum.text && !datum.emoticons.length) {
|
|
|
|
|
datum.emoticons = [datum.text]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete datum.text
|
|
|
|
|
delete datum.texts
|
|
|
|
|
|
2016-06-09 01:30:41 +00:00
|
|
|
|
if (datum.category == 'Skin Tones') {
|
2016-05-31 20:42:22 +00:00
|
|
|
|
data.skins[datum.short_name] = datum
|
|
|
|
|
} else {
|
|
|
|
|
categoryIndex = categoriesIndex[category]
|
|
|
|
|
data.categories[categoryIndex].emojis.push(datum.short_name)
|
|
|
|
|
data.emojis[datum.short_name] = datum
|
|
|
|
|
}
|
2016-05-31 14:36:52 +00:00
|
|
|
|
})
|
|
|
|
|
|
2016-07-07 17:34:03 +00:00
|
|
|
|
var flags = data.categories[categoriesIndex['Flags']];
|
|
|
|
|
flags.emojis.sort()
|
|
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
|
mkdirp('data', (err) => {
|
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
|
|
fs.writeFile('data/index.js', `export default ${JSON.stringify(data)}`, (err) => {
|
|
|
|
|
if (err) throw err
|
|
|
|
|
})
|
|
|
|
|
})
|