Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compress data #111

Merged
merged 2 commits into from
Sep 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
})
})