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/
data/
data/data.js
dist/
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"
},
"scripts": {
"clean": "rimraf data/ dist/",
"clean": "rimraf data/data.js dist/",
"clean:dist": "rm -rf dist/",
"build:data": "node scripts/build-data",
"build:example": "node scripts/build-example",
@ -72,7 +72,7 @@
"size-limit": [
{
"path": "dist/index.js",
"limit": "99 KB"
"limit": "88 KB"
}
]
}

View File

@ -2,8 +2,7 @@ var fs = require('fs'),
emojiData = require('emoji-datasource'),
emojiLib = require('emojilib'),
inflection = require('inflection'),
mkdirp = require('mkdirp'),
buildSearch = require('../src/utils/build-search')
mkdirp = require('mkdirp')
var unifiedToNative = unified => String.fromCodePoint(
...unified.split('-').map(s => parseInt(s, 16))
@ -92,18 +91,9 @@ emojiData.forEach((datum) => {
delete datum.texts
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') {
data.skins[datum.short_name] = datum
} else {
@ -117,6 +107,12 @@ emojiData.forEach((datum) => {
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.au
delete datum.softbank
@ -125,6 +121,8 @@ emojiData.forEach((datum) => {
delete datum.short_name
delete datum.category
delete datum.sort_order
delete datum.sheet_x
delete datum.sheet_y
for (let key in datum) {
let value = datum[key]
@ -142,7 +140,7 @@ mkdirp('data', (err) => {
if (err) throw err
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
})
})