Skip to content

Commit

Permalink
Merge pull request #276 from mimi89999/compression
Browse files Browse the repository at this point in the history
feat(package)!: add dictionary compression
  • Loading branch information
MrWook authored Sep 28, 2024
2 parents fffe4c4 + c317614 commit 3c304eb
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 21 deletions.
6 changes: 5 additions & 1 deletion packages/languages/ar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"arabic"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"common"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/cs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"czech"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/da-dk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"danish"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/de/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"german"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/en/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"english"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/es-es/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
"translation",
"spanish",
"spain"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/fi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"finnish"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/fr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"french"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"indonesia"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/it/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"italian"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/ja/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
"language",
"translation",
"japanese"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/nl-be/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
"translation",
"dutch",
"belgium"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/pl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@
"polish",
"poland",
"pl"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
6 changes: 5 additions & 1 deletion packages/languages/pt-br/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@
"portuguese",
"pt-br",
"ptbr"
]
],
"dependencies": {
"@alttiri/base85": "^1.8.0",
"fflate": "^0.8.2"
}
}
28 changes: 24 additions & 4 deletions scripts/jsonPlugin.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { compressSync, strToU8 } from 'fflate'
import { encodeBase85 } from '@alttiri/base85'

const json = () => {
return {
name: 'json',
Expand All @@ -10,11 +13,28 @@ const json = () => {

try {
const parsed = JSON.parse(json)
const data = Array.isArray(parsed)
? `"${parsed.join(',')}".split(',')`
: JSON.stringify(parsed)
var code
if (Array.isArray(parsed)) {
const data = parsed.join(',')
const data_buf = strToU8(data)
const compressed = compressSync(data_buf, { level: 9, mem: 12 })
const encoded = encodeBase85(compressed)

code = `
import { decompressSync, strFromU8 } from 'fflate'
import { decodeBase85 } from '@alttiri/base85'
const code = `export default ${data}`
const encoded = "${encoded}"
const decoded = decodeBase85(encoded)
const decompressed_buf = decompressSync(decoded)
const decompressed = strFromU8(decompressed_buf);
const decompressed_array = decompressed.split(',')
export default decompressed_array`
} else {
const data = JSON.stringify(parsed)
code = `export default ${data}`
}

return {
code,
Expand Down
4 changes: 2 additions & 2 deletions scripts/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ const generateConfig = async (type, minify = false) => {
}

if (type === 'iife') {
pluginsOnlyOnce.push(nodeResolve({ resolveOnly: ['fastest-levenshtein'] }))
pluginsOnlyOnce.push(nodeResolve({ resolveOnly: ['fastest-levenshtein', '@alttiri/base85', 'fflate'] }))
} else {
external.push('fastest-levenshtein')
external.push('fastest-levenshtein', '@alttiri/base85', 'fflate')
}

return {
Expand Down

0 comments on commit 3c304eb

Please sign in to comment.