2016-07-07 17:35:22 +00:00
|
|
|
|
var fs = require('fs'),
|
2016-11-30 22:59:31 +00:00
|
|
|
|
emojiData = require('emoji-datasource'),
|
2016-07-21 20:06:13 +00:00
|
|
|
|
emojiLib = require('emojilib'),
|
2016-07-07 17:35:22 +00:00
|
|
|
|
inflection = require('inflection'),
|
2017-05-24 16:34:10 +00:00
|
|
|
|
mkdirp = require('mkdirp'),
|
|
|
|
|
buildSearch = require('../src/utils/build-search')
|
2016-07-21 20:06:13 +00:00
|
|
|
|
|
2017-08-06 18:02:14 +00:00
|
|
|
|
var unifiedToNative = unified => String.fromCodePoint(
|
|
|
|
|
...unified.split('-').map(s => parseInt(s, 16))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Turn this:
|
|
|
|
|
//
|
|
|
|
|
// "uruguay": {
|
|
|
|
|
// "keywords": ["uy", "flag", "nation", "country", "banner"],
|
|
|
|
|
// "char": "🇺🇾",
|
|
|
|
|
// "fitzpatrick_scale": false,
|
|
|
|
|
// "category": "flags"
|
|
|
|
|
// },
|
|
|
|
|
//
|
|
|
|
|
// into this:
|
|
|
|
|
//
|
|
|
|
|
// "🇺🇾": {
|
|
|
|
|
// "name": "uruguay",
|
|
|
|
|
// "keywords": ["uruguay", "uy", "flag", "nation", "country", "banner"],
|
|
|
|
|
// "char": "🇺🇾",
|
|
|
|
|
// "fitzpatrick_scale": false,
|
|
|
|
|
// "category": "flags"
|
|
|
|
|
// },
|
|
|
|
|
var emojiLibByChar = Object.keys(emojiLib.lib).reduce(
|
|
|
|
|
(acc, shortName) => {
|
|
|
|
|
var data = Object.assign({}, emojiLib.lib[shortName])
|
|
|
|
|
|
|
|
|
|
data.keywords.unshift(shortName)
|
|
|
|
|
data.name = shortName
|
|
|
|
|
|
|
|
|
|
acc[data.char] = data
|
|
|
|
|
|
|
|
|
|
return acc
|
|
|
|
|
},
|
|
|
|
|
{}
|
|
|
|
|
)
|
|
|
|
|
|
2016-07-07 17:35:22 +00:00
|
|
|
|
var categories = ['People', 'Nature', 'Foods', 'Activity', 'Places', 'Objects', 'Symbols', 'Flags'],
|
2016-10-13 20:19:46 +00:00
|
|
|
|
data = { categories: [], emojis: {}, skins: {}, short_names: {} },
|
2016-07-07 17:35:22 +00:00
|
|
|
|
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,
|
2016-07-21 20:06:13 +00:00
|
|
|
|
keywords = [],
|
2017-08-06 18:02:14 +00:00
|
|
|
|
categoryIndex,
|
|
|
|
|
char = unifiedToNative(datum.unified),
|
|
|
|
|
emojiLibMatch = emojiLibByChar[char]
|
2016-05-31 14:36:52 +00:00
|
|
|
|
|
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, ' '))
|
2017-08-06 18:02:14 +00:00
|
|
|
|
|
|
|
|
|
if (datum.category == 'Flags' && emojiLibMatch) {
|
|
|
|
|
// prefer name from emojiLib ("Uruguay")
|
|
|
|
|
// instead of emojiData ("REGIONAL INDICATOR SYMBOL LETTERS UY")
|
|
|
|
|
datum.name = emojiLibMatch.name
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
|
datum.name = inflection.titleize(datum.name || '')
|
|
|
|
|
|
Country names: correctly uppercase names like 'EU'
Always perform the capitalization-correction for country names. If we
did this naïvely, using the same regex as before, it would change things
like "Falkland Islands" to "Falkland ISLANDS". The new regex checks on
word boundary, `\b`, instead of space, `\s`, which means even single
words like `Eu` are found. It then checks for exactly two letters, where
the first is uppercase and the second lowercase.
Here's exactly what it affects:
* All "Regional Indicator Symbol Letters AC"-type names that don't
have data in emojiLib
* There are some flags in emojiLib for which it uses two-character
abbreviations instead of full country names (see muan/emojilib#131).
These countries are: CN, EU, FR, DE, IT, JP, RU, KR, ES, TR, UK, US
This new regex corrects these from Cn, Eu, Fr, etc.
2017-08-06 18:05:01 +00:00
|
|
|
|
if (datum.category == 'Flags') {
|
|
|
|
|
// uppercase two-letter country codes
|
|
|
|
|
datum.name = datum.name.replace(/\b[A-Z]([a-z])$/, letters => letters.toUpperCase())
|
2016-07-07 17:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
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 || []
|
2017-05-31 19:17:20 +00:00
|
|
|
|
datum.text = datum.text || ''
|
2016-07-07 21:22:40 +00:00
|
|
|
|
delete datum.texts
|
|
|
|
|
|
2017-08-06 18:02:14 +00:00
|
|
|
|
if (emojiLibMatch) {
|
|
|
|
|
keywords = emojiLibMatch.keywords
|
2016-07-21 20:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 16:34:10 +00:00
|
|
|
|
datum.search = buildSearch({
|
|
|
|
|
short_names: datum.short_names,
|
|
|
|
|
name: datum.name,
|
|
|
|
|
keywords,
|
|
|
|
|
emoticons: datum.emoticons
|
|
|
|
|
})
|
2016-07-26 18:50:55 +00:00
|
|
|
|
|
|
|
|
|
datum.search = datum.search.join(',')
|
2016-07-21 20:06:13 +00:00
|
|
|
|
|
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-07-22 16:23:47 +00:00
|
|
|
|
|
2016-10-13 20:19:46 +00:00
|
|
|
|
datum.short_names.forEach((short_name, i) => {
|
|
|
|
|
if (i == 0) { return }
|
|
|
|
|
data.short_names[short_name] = datum.short_name
|
|
|
|
|
})
|
|
|
|
|
|
2016-07-22 16:23:47 +00:00
|
|
|
|
delete datum.docomo
|
|
|
|
|
delete datum.au
|
|
|
|
|
delete datum.softbank
|
|
|
|
|
delete datum.google
|
|
|
|
|
delete datum.image
|
|
|
|
|
delete datum.short_name
|
|
|
|
|
delete datum.category
|
|
|
|
|
delete datum.sort_order
|
2017-03-10 17:11:05 +00:00
|
|
|
|
|
|
|
|
|
for (let key in datum) {
|
|
|
|
|
let value = datum[key]
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(value) && !value.length) {
|
|
|
|
|
delete datum[key]
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-31 14:36:52 +00:00
|
|
|
|
})
|
|
|
|
|
|
2017-04-04 16:00:32 +00:00
|
|
|
|
var flags = data.categories[categoriesIndex['Flags']]
|
2016-07-07 17:34:03 +00:00
|
|
|
|
flags.emojis.sort()
|
|
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
|
mkdirp('data', (err) => {
|
|
|
|
|
if (err) throw err
|
|
|
|
|
|
2017-03-02 18:55:01 +00:00
|
|
|
|
const stringifiedData = JSON.stringify(data).replace(/\"([A-Za-z_]+)\":/g, '$1:')
|
|
|
|
|
fs.writeFile('data/index.js', `export default ${stringifiedData}`, (err) => {
|
2016-05-31 14:36:52 +00:00
|
|
|
|
if (err) throw err
|
|
|
|
|
})
|
|
|
|
|
})
|