Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compress emoji_data_light.js (#5201)
- Loading branch information
1 parent
875d943
commit 82d9ade
Showing
2 changed files
with
35 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @preval | ||
const data = require('emoji-mart/dist/data').default; | ||
const pick = require('lodash/pick'); | ||
const values = require('lodash/values'); | ||
|
||
const condensedEmojis = Object.keys(data.emojis).map(key => { | ||
if (!data.emojis[key].short_names[0] === key) { | ||
throw new Error('The condenser expects the first short_code to be the ' + | ||
'key. It may need to be rewritten if the emoji change such that this ' + | ||
'is no longer the case.'); | ||
} | ||
return values(pick(data.emojis[key], ['short_names', 'unified', 'search'])); | ||
}); | ||
|
||
// JSON.parse/stringify is to emulate what @preval is doing and avoid any | ||
// inconsistent behavior in dev mode | ||
module.exports = JSON.parse(JSON.stringify({ | ||
emojis: condensedEmojis, | ||
skins: data.skins, | ||
categories: data.categories, | ||
short_names: data.short_names, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
// @preval | ||
const data = require('emoji-mart/dist/data').default; | ||
const pick = require('lodash/pick'); | ||
const data = require('./emoji_data_compressed'); | ||
|
||
const condensedEmojis = {}; | ||
Object.keys(data.emojis).forEach(key => { | ||
condensedEmojis[key] = pick(data.emojis[key], ['short_names', 'unified', 'search']); | ||
// decompress | ||
const emojis = {}; | ||
data.emojis.forEach(compressedEmoji => { | ||
const [ short_names, unified, search ] = compressedEmoji; | ||
emojis[short_names[0]] = { | ||
short_names, | ||
unified, | ||
search, | ||
}; | ||
}); | ||
|
||
// JSON.parse/stringify is to emulate what @preval is doing and avoid any | ||
// inconsistent behavior in dev mode | ||
module.exports = JSON.parse(JSON.stringify({ | ||
emojis: condensedEmojis, | ||
skins: data.skins, | ||
categories: data.categories, | ||
short_names: data.short_names, | ||
})); | ||
data.emojis = emojis; | ||
|
||
module.exports = data; |