From c317614cd758416a71f9adcb2e9d7caf125a23f7 Mon Sep 17 00:00:00 2001 From: mimi89999 Date: Wed, 25 Sep 2024 15:44:13 +0200 Subject: [PATCH] feat(package): add dictionary compression --- packages/languages/ar/package.json | 6 +++++- packages/languages/common/package.json | 6 +++++- packages/languages/cs/package.json | 6 +++++- packages/languages/da-dk/package.json | 6 +++++- packages/languages/de/package.json | 6 +++++- packages/languages/en/package.json | 6 +++++- packages/languages/es-es/package.json | 6 +++++- packages/languages/fi/package.json | 6 +++++- packages/languages/fr/package.json | 6 +++++- packages/languages/id/package.json | 6 +++++- packages/languages/it/package.json | 6 +++++- packages/languages/ja/package.json | 6 +++++- packages/languages/nl-be/package.json | 6 +++++- packages/languages/pl/package.json | 6 +++++- packages/languages/pt-br/package.json | 6 +++++- scripts/jsonPlugin.mjs | 28 ++++++++++++++++++++++---- scripts/rollup.config.mjs | 4 ++-- 17 files changed, 101 insertions(+), 21 deletions(-) diff --git a/packages/languages/ar/package.json b/packages/languages/ar/package.json index 1807e3e9..b2c78a85 100644 --- a/packages/languages/ar/package.json +++ b/packages/languages/ar/package.json @@ -25,5 +25,9 @@ "language", "translation", "arabic" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/common/package.json b/packages/languages/common/package.json index ab8fb9d8..ee9486b3 100644 --- a/packages/languages/common/package.json +++ b/packages/languages/common/package.json @@ -25,5 +25,9 @@ "language", "translation", "common" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/cs/package.json b/packages/languages/cs/package.json index 243573db..d4ccb976 100644 --- a/packages/languages/cs/package.json +++ b/packages/languages/cs/package.json @@ -25,5 +25,9 @@ "language", "translation", "czech" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/da-dk/package.json b/packages/languages/da-dk/package.json index fefbdb38..6977a499 100644 --- a/packages/languages/da-dk/package.json +++ b/packages/languages/da-dk/package.json @@ -25,5 +25,9 @@ "language", "translation", "danish" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/de/package.json b/packages/languages/de/package.json index b2ebf481..4e8246d4 100644 --- a/packages/languages/de/package.json +++ b/packages/languages/de/package.json @@ -25,5 +25,9 @@ "language", "translation", "german" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/en/package.json b/packages/languages/en/package.json index a66ea974..865ef84b 100644 --- a/packages/languages/en/package.json +++ b/packages/languages/en/package.json @@ -25,5 +25,9 @@ "language", "translation", "english" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/es-es/package.json b/packages/languages/es-es/package.json index 2b893206..5acac336 100644 --- a/packages/languages/es-es/package.json +++ b/packages/languages/es-es/package.json @@ -26,5 +26,9 @@ "translation", "spanish", "spain" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/fi/package.json b/packages/languages/fi/package.json index 686d047e..c5c25af8 100644 --- a/packages/languages/fi/package.json +++ b/packages/languages/fi/package.json @@ -25,5 +25,9 @@ "language", "translation", "finnish" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/fr/package.json b/packages/languages/fr/package.json index 99b35ec0..5bcd600e 100644 --- a/packages/languages/fr/package.json +++ b/packages/languages/fr/package.json @@ -25,5 +25,9 @@ "language", "translation", "french" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/id/package.json b/packages/languages/id/package.json index 705f98e7..b90d76d2 100644 --- a/packages/languages/id/package.json +++ b/packages/languages/id/package.json @@ -25,5 +25,9 @@ "language", "translation", "indonesia" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/it/package.json b/packages/languages/it/package.json index fa4ba2a2..54e00288 100644 --- a/packages/languages/it/package.json +++ b/packages/languages/it/package.json @@ -25,5 +25,9 @@ "language", "translation", "italian" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/ja/package.json b/packages/languages/ja/package.json index d2539134..73b4245b 100644 --- a/packages/languages/ja/package.json +++ b/packages/languages/ja/package.json @@ -25,5 +25,9 @@ "language", "translation", "japanese" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/nl-be/package.json b/packages/languages/nl-be/package.json index b1f04f30..b594d924 100644 --- a/packages/languages/nl-be/package.json +++ b/packages/languages/nl-be/package.json @@ -26,5 +26,9 @@ "translation", "dutch", "belgium" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/pl/package.json b/packages/languages/pl/package.json index a20f7fa3..48653337 100644 --- a/packages/languages/pl/package.json +++ b/packages/languages/pl/package.json @@ -27,5 +27,9 @@ "polish", "poland", "pl" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/packages/languages/pt-br/package.json b/packages/languages/pt-br/package.json index e4e73cb2..7cd6a863 100644 --- a/packages/languages/pt-br/package.json +++ b/packages/languages/pt-br/package.json @@ -29,5 +29,9 @@ "portuguese", "pt-br", "ptbr" - ] + ], + "dependencies": { + "@alttiri/base85": "^1.8.0", + "fflate": "^0.8.2" + } } diff --git a/scripts/jsonPlugin.mjs b/scripts/jsonPlugin.mjs index 5c17f8bf..8861c1d6 100644 --- a/scripts/jsonPlugin.mjs +++ b/scripts/jsonPlugin.mjs @@ -1,3 +1,6 @@ +import { compressSync, strToU8 } from 'fflate' +import { encodeBase85 } from '@alttiri/base85' + const json = () => { return { name: 'json', @@ -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, diff --git a/scripts/rollup.config.mjs b/scripts/rollup.config.mjs index e4321df6..5426acee 100644 --- a/scripts/rollup.config.mjs +++ b/scripts/rollup.config.mjs @@ -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 {