Merge pull request #111 from ai/compress-data

Compress data
release
Etienne Lemay 2017-09-13 17:08:36 -04:00 committed by GitHub
commit 9bf9eb699f
4 changed files with 46 additions and 16 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
node_modules/ node_modules/
data/ data/data.js
dist/ dist/
bundle.js bundle.js

32
data/index.js Normal file
View File

@ -0,0 +1,32 @@
var buildSearch = require('../src/utils/build-search')
var data = require('./data')
function uncompress (list) {
for (var short_name in list) {
var datum = list[short_name]
if (!datum.short_names) datum.short_names = []
datum.short_names.unshift(short_name)
datum.sheet_x = datum.sheet[0]
datum.sheet_y = datum.sheet[1]
delete datum.sheet
if (!datum.text) datum.text = ''
if (datum.added_in !== null && !datum.added_in) datum.added_in = '6.0'
datum.search = buildSearch({
short_names: datum.short_names,
name: datum.name,
keywords: datum.keywords,
emoticons: datum.emoticons
})
datum.search = datum.search.join(',')
}
}
uncompress(data.emojis)
uncompress(data.skins)
module.exports = data

View File

@ -55,7 +55,7 @@
"webpack": "1.12.14" "webpack": "1.12.14"
}, },
"scripts": { "scripts": {
"clean": "rimraf data/ dist/", "clean": "rimraf data/data.js dist/",
"clean:dist": "rm -rf dist/", "clean:dist": "rm -rf dist/",
"build:data": "node scripts/build-data", "build:data": "node scripts/build-data",
"build:example": "node scripts/build-example", "build:example": "node scripts/build-example",
@ -72,7 +72,7 @@
"size-limit": [ "size-limit": [
{ {
"path": "dist/index.js", "path": "dist/index.js",
"limit": "99 KB" "limit": "88 KB"
} }
] ]
} }

View File

@ -2,8 +2,7 @@ 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 unifiedToNative = unified => String.fromCodePoint( var unifiedToNative = unified => String.fromCodePoint(
...unified.split('-').map(s => parseInt(s, 16)) ...unified.split('-').map(s => parseInt(s, 16))
@ -92,18 +91,9 @@ emojiData.forEach((datum) => {
delete datum.texts delete datum.texts
if (emojiLibMatch) { if (emojiLibMatch) {
keywords = emojiLibMatch.keywords datum.keywords = emojiLibMatch.keywords
} }
datum.search = buildSearch({
short_names: datum.short_names,
name: datum.name,
keywords,
emoticons: datum.emoticons
})
datum.search = datum.search.join(',')
if (datum.category == 'Skin Tones') { if (datum.category == 'Skin Tones') {
data.skins[datum.short_name] = datum data.skins[datum.short_name] = datum
} else { } else {
@ -117,6 +107,12 @@ emojiData.forEach((datum) => {
data.short_names[short_name] = datum.short_name data.short_names[short_name] = datum.short_name
}) })
datum.short_names = datum.short_names.filter(i => i !== datum.short_name)
datum.sheet = [datum.sheet_x, datum.sheet_y]
if (datum.text === '') delete datum.text
if (datum.added_in === '6.0') delete datum.added_in
delete datum.docomo delete datum.docomo
delete datum.au delete datum.au
delete datum.softbank delete datum.softbank
@ -125,6 +121,8 @@ emojiData.forEach((datum) => {
delete datum.short_name delete datum.short_name
delete datum.category delete datum.category
delete datum.sort_order delete datum.sort_order
delete datum.sheet_x
delete datum.sheet_y
for (let key in datum) { for (let key in datum) {
let value = datum[key] let value = datum[key]
@ -142,7 +140,7 @@ mkdirp('data', (err) => {
if (err) throw err if (err) throw err
const stringified = JSON.stringify(data).replace(/\"([A-Za-z_]+)\":/g, '$1:') const stringified = JSON.stringify(data).replace(/\"([A-Za-z_]+)\":/g, '$1:')
fs.writeFile('data/index.js', `module.exports = ${stringified}`, (err) => { fs.writeFile('data/data.js', `module.exports = ${stringified}`, (err) => {
if (err) throw err if (err) throw err
}) })
}) })