Split out generation of search property
parent
00dce20f0f
commit
d9c0139d73
|
@ -2,7 +2,8 @@ var fs = require('fs'),
|
||||||
emojiData = require('emoji-datasource'),
|
emojiData = require('emoji-datasource'),
|
||||||
emojiLib = require('emojilib'),
|
emojiLib = require('emojilib'),
|
||||||
inflection = require('inflection'),
|
inflection = require('inflection'),
|
||||||
mkdirp = require('mkdirp')
|
mkdirp = require('mkdirp'),
|
||||||
|
buildSearch = require('../src/utils/build-search')
|
||||||
|
|
||||||
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: {} },
|
||||||
|
@ -52,23 +53,12 @@ emojiData.forEach((datum) => {
|
||||||
keywords = emojiLib.lib[datum.short_name].keywords
|
keywords = emojiLib.lib[datum.short_name].keywords
|
||||||
}
|
}
|
||||||
|
|
||||||
datum.search = []
|
datum.search = buildSearch({
|
||||||
var addToSearch = (strings, split) => {
|
short_names: datum.short_names,
|
||||||
(Array.isArray(strings) ? strings : [strings]).forEach((string) => {
|
name: datum.name,
|
||||||
(split ? string.split(/[-|_|\s]+/) : [string]).forEach((s) => {
|
keywords,
|
||||||
s = s.toLowerCase()
|
emoticons: datum.emoticons
|
||||||
|
|
||||||
if (datum.search.indexOf(s) == -1) {
|
|
||||||
datum.search.push(s)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
addToSearch(datum.short_names, true)
|
|
||||||
addToSearch(datum.name, true)
|
|
||||||
addToSearch(keywords, false)
|
|
||||||
addToSearch(datum.emoticons, false)
|
|
||||||
|
|
||||||
datum.search = datum.search.join(',')
|
datum.search = datum.search.join(',')
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
module.exports = data => {
|
||||||
|
const search = []
|
||||||
|
|
||||||
|
var addToSearch = (strings, split) => {
|
||||||
|
(Array.isArray(strings) ? strings : [strings]).forEach((string) => {
|
||||||
|
(split ? string.split(/[-|_|\s]+/) : [string]).forEach((s) => {
|
||||||
|
s = s.toLowerCase()
|
||||||
|
|
||||||
|
if (search.indexOf(s) == -1) {
|
||||||
|
search.push(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
addToSearch(data.short_names, true)
|
||||||
|
addToSearch(data.name, true)
|
||||||
|
addToSearch(data.keywords, false)
|
||||||
|
addToSearch(data.emoticons, false)
|
||||||
|
|
||||||
|
return search
|
||||||
|
}
|
Loading…
Reference in New Issue