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

[#107] Extract compress method (used by build script) #112

Merged
merged 1 commit into from
Mar 20, 2021
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 scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var fs = require('fs'),
emojiLib = require('emojilib'),
inflection = require('inflection')

var { compress } = require('../src/utils/data')
var { compress } = require('./compress')

var categories = [
['Smileys & Emotion', 'smileys'],
Expand Down
50 changes: 50 additions & 0 deletions scripts/compress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const mapping = {
name: 'a',
unified: 'b',
non_qualified: 'c',
has_img_apple: 'd',
has_img_google: 'e',
has_img_twitter: 'f',
has_img_facebook: 'h',
keywords: 'j',
sheet: 'k',
emoticons: 'l',
text: 'm',
short_names: 'n',
added_in: 'o',
}

const compress = (emoji) => {
emoji.short_names = emoji.short_names.filter((short_name) => {
return short_name !== emoji.short_name
})
delete emoji.short_name

emoji.sheet = [emoji.sheet_x, emoji.sheet_y]
delete emoji.sheet_x
delete emoji.sheet_y

emoji.added_in = parseInt(emoji.added_in)
if (emoji.added_in === 6) {
delete emoji.added_in
}

for (let key in mapping) {
emoji[mapping[key]] = emoji[key]
delete emoji[key]
}

for (let key in emoji) {
let value = emoji[key]

if (Array.isArray(value) && !value.length) {
delete emoji[key]
} else if (typeof value === 'string' && !value.length) {
delete emoji[key]
} else if (value === null) {
delete emoji[key]
}
}
}

module.exports = { compress }
35 changes: 1 addition & 34 deletions src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,6 @@ const buildSearch = (emoji) => {
return search.join(',')
}

const compress = (emoji) => {
emoji.short_names = emoji.short_names.filter((short_name) => {
return short_name !== emoji.short_name
})
delete emoji.short_name

emoji.sheet = [emoji.sheet_x, emoji.sheet_y]
delete emoji.sheet_x
delete emoji.sheet_y

emoji.added_in = parseInt(emoji.added_in)
if (emoji.added_in === 6) {
delete emoji.added_in
}

for (let key in mapping) {
emoji[mapping[key]] = emoji[key]
delete emoji[key]
}

for (let key in emoji) {
let value = emoji[key]

if (Array.isArray(value) && !value.length) {
delete emoji[key]
} else if (typeof value === 'string' && !value.length) {
delete emoji[key]
} else if (value === null) {
delete emoji[key]
}
}
}

function deepFreeze(object) {
// Retrieve the property names defined on object
var propNames = Object.getOwnPropertyNames(object)
Expand Down Expand Up @@ -119,4 +86,4 @@ const uncompress = (data) => {
return data
}

export { buildSearch, compress, uncompress }
export { buildSearch, uncompress }