Skip to content

Commit

Permalink
Merge pull request #111 from ai/compress-data
Browse files Browse the repository at this point in the history
Compress data
  • Loading branch information
EtienneLem authored Sep 13, 2017
2 parents 6fe496a + 7e9232a commit 9bf9eb6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules/
data/
data/data.js
dist/
bundle.js
32 changes: 32 additions & 0 deletions data/index.js
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -72,7 +72,7 @@
"size-limit": [
{
"path": "dist/index.js",
"limit": "99 KB"
"limit": "88 KB"
}
]
}
24 changes: 11 additions & 13 deletions scripts/build-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
})
})

0 comments on commit 9bf9eb6

Please sign in to comment.