Country flag names: use name from emojiLib

* Always match on emoji character
* For flag emojis where emojiLib data is found, use emojiLib name
release
Chad Ostrowski 2017-08-06 14:02:14 -04:00
parent c21e1402b6
commit 22adc985b8
1 changed files with 49 additions and 4 deletions

View File

@ -5,6 +5,42 @@ var fs = require('fs'),
mkdirp = require('mkdirp'), mkdirp = require('mkdirp'),
buildSearch = require('../src/utils/build-search') buildSearch = require('../src/utils/build-search')
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
},
{}
)
var categories = ['People', 'Nature', 'Foods', 'Activity', 'Places', 'Objects', 'Symbols', 'Flags'], var categories = ['People', 'Nature', 'Foods', 'Activity', 'Places', 'Objects', 'Symbols', 'Flags'],
data = { categories: [], emojis: {}, skins: {}, short_names: {} }, data = { categories: [], emojis: {}, skins: {}, short_names: {} },
categoriesIndex = {} categoriesIndex = {}
@ -24,16 +60,25 @@ emojiData.sort((a, b) => {
emojiData.forEach((datum) => { emojiData.forEach((datum) => {
var category = datum.category, var category = datum.category,
keywords = [], keywords = [],
categoryIndex categoryIndex,
char = unifiedToNative(datum.unified),
emojiLibMatch = emojiLibByChar[char]
if (!datum.category) { if (!datum.category) {
throw new Error('“' + datum.short_name + '” doesnt have a category') throw new Error('“' + datum.short_name + '” doesnt have a category')
} }
datum.name || (datum.name = datum.short_name.replace(/\-/g, ' ')) datum.name || (datum.name = datum.short_name.replace(/\-/g, ' '))
if (datum.category == 'Flags' && emojiLibMatch) {
// prefer name from emojiLib ("Uruguay")
// instead of emojiData ("REGIONAL INDICATOR SYMBOL LETTERS UY")
datum.name = emojiLibMatch.name
}
datum.name = inflection.titleize(datum.name || '') datum.name = inflection.titleize(datum.name || '')
if (datum.category == 'Flags') { if (datum.category == 'Flags' && !emojiLibMatch) {
datum.name = datum.name.replace(/\s(\w+)$/, (letters) => letters.toUpperCase()) datum.name = datum.name.replace(/\s(\w+)$/, (letters) => letters.toUpperCase())
} }
@ -45,8 +90,8 @@ emojiData.forEach((datum) => {
datum.text = datum.text || '' datum.text = datum.text || ''
delete datum.texts delete datum.texts
if (emojiLib.lib[datum.short_name]) { if (emojiLibMatch) {
keywords = emojiLib.lib[datum.short_name].keywords keywords = emojiLibMatch.keywords
} }
datum.search = buildSearch({ datum.search = buildSearch({