From 4d2bac86c077ee518356a0928e5ca9b88451de41 Mon Sep 17 00:00:00 2001 From: networkmastered Date: Tue, 11 Mar 2025 00:27:05 +0000 Subject: [PATCH] ver bump V1.1.0 --- .gitignore | 3 ++ archive/testchecks.js | 74 +++++++++++++++++++++++++++++++++++++++++++ main.ts | 13 ++++++-- package.json | 4 +-- 4 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 archive/testchecks.js diff --git a/.gitignore b/.gitignore index 386ac2b..f05821a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ data.json # Exclude macOS Finder (System Explorer) View States .DS_Store + +util/dictionaryBIGUnusedWiki.json +util/temp.js diff --git a/archive/testchecks.js b/archive/testchecks.js new file mode 100644 index 0000000..f5b2ce7 --- /dev/null +++ b/archive/testchecks.js @@ -0,0 +1,74 @@ +const { encodeSafe, decodeSafe } = require("../util/runlength") +const LZ = require("../util/runlengthMatch") +const { netcompress, netdecompress } = require("../util/networkmastercompression") +const funcs = [netcompress, netdecompress, encodeSafe, decodeSafe, LZ.compress, LZ.decompress] +const names = ["netcompress", "netdecompress", "encodeSafe", "decodeSafe", "LZcompress", "LZdecompress"] + +const tests = [ + { type: 0, inputs: ["hi", "type1"], output: "gAfoE" }, + { type: 0, inputs: ["hi,", "type1"], output: "gAundefined" }, + { type: 0, inputs: ["abcdefg formats", "type2"], output: "ABfUBiQDRURGdESBcEUT5kQVRF" }, + { type: 0, inputs: ["master file true", "type3"], output: "gBfoOabmMbXmNdL31dZA" }, + { type: 0, inputs: ["zygote", "type3"], output: "gBf8_D" }, + { type: 0, inputs: ["zygotezygote", "type3"], output: "gBf8_z_P" }, + { type: 0, inputs: ["hello World", "type4"], output: "ACfhello World" }, + { type: 0, inputs: ["test test test test test", "type5"], output: "gCfgw2AhtBCbDE2GIsB" }, + { type: 1, inputs: ["gAfoE"], output: "hi" }, + { type: 1, inputs: ["ACfhello World"], output: "hello World" }, + { type: 1, inputs: ["gCfgw2AhtBCbDE2GIsB"], output: "test test test test test" }, + { type: 2, inputs: ["A"], output: "A" }, + { type: 2, inputs: ["AA"], output: "AA" }, + { type: 2, inputs: ["AAA"], output: "óA" }, + { type: 2, inputs: ["AAAA"], output: "úA" }, + { type: 2, inputs: ["AAAAA"], output: "üA" }, + { type: 2, inputs: ["AAAAAA"], output: "ñA" }, + { type: 2, inputs: ["AAAAAAA"], output: "çA" }, + { type: 2, inputs: ["AAAAAAAA"], output: "¿A" }, + { type: 2, inputs: ["AAAAAAAAA"], output: "¡A" }, + { type: 2, inputs: ["AAAAAAAAAA"], output: "éáA" }, + { type: 2, inputs: ["AAAAAAAAAAA"], output: "ééA" }, + { type: 2, inputs: ["AAAAAAAAAAAA"], output: "éíA" }, + { type: 3, inputs: ["A"], output: "A" }, + { type: 3, inputs: ["AA"], output: "AA" }, + { type: 3, inputs: ["óA"], output: "AAA" }, + { type: 3, inputs: ["úA"], output: "AAAA" }, + { type: 3, inputs: ["üA"], output: "AAAAA" }, + { type: 3, inputs: ["ñA"], output: "AAAAAA" }, + { type: 3, inputs: ["çA"], output: "AAAAAAA" }, + { type: 3, inputs: ["¿A"], output: "AAAAAAAA" }, + { type: 3, inputs: ["¡A"], output: "AAAAAAAAA" }, + { type: 3, inputs: ["éáA"], output: "AAAAAAAAAA" }, + { type: 3, inputs: ["ééA"], output: "AAAAAAAAAAA" }, + { type: 3, inputs: ["éíA"], output: "AAAAAAAAAAAA" }, + // { type: 0, inputs: ["hi"], output: "" }, +] + +var pass = 0 +var fail = 0 + +for (let idx = 0; idx < tests.length; idx++) { + let test = tests[idx] + var name = names[test.type] + var func = funcs[test.type] + var out = "" + try { + out = func(...test.inputs) + } catch (err) { + throw new Error(err) + } + if (test.output == out) { + console.log(`\u001b[32mTest ${name} ${idx + 1}. Passed ✔\u001b[30m`) + pass++ + } else { + console.log(`\u001b[31mTest ${name} ${idx + 1}. Failed ❌(${out} ~= ${test.output})\u001b[30m`) + fail++ + } +} + +console.log(`Finished. \u001b[32m${pass} have passed\u001b[31m ${fail} have failed \u001b[32m${pass}\u001b[30m/\u001b[31m${fail}\u001b[30m`) + +if (fail > 0) { + + throw new Error("failed") + +} \ No newline at end of file diff --git a/main.ts b/main.ts index 022a34e..8ee44d5 100644 --- a/main.ts +++ b/main.ts @@ -44,7 +44,8 @@ export default class compressorPlugin extends Plugin { hook.editor.refresh = () => { } globalLeafs.push(["ctxt", file.path, hook]) this.app.vault.read(file).then((data) => { - if (file && data && (!data.includes("\n") && !data.includes(" "))) { + // if (file && data && (!data.includes("\n") && !data.includes(" "))) { + if (file && data && checkCompFile(data)) { new Notice("Attempting to load.") setTimeout(() => { let decompress = null @@ -81,7 +82,8 @@ export default class compressorPlugin extends Plugin { if (file2 && file2.extension == "ctxt") { this.app.vault.read(file2).then((data) => { if (statusBarItemEl2 && this.settings.FileSize) statusBarItemEl2.setText(data.length + "B") - if (file2 && data && (data.includes("\n") || data.includes(" "))) { + // if (file2 && data && (data.includes("\n") || data.includes(" "))) { + if (file2 && data && checkCompFile(data)) { let compress = null try { NoticePool.forEach((n) => { @@ -343,6 +345,13 @@ function decompressfile(data: string, notice?: boolean) { if (result == "" || !result) throw new Error("Empty") return result } +function checkCompFile(data: string) { + var state = false + try { + state = netdecompress(data) == "" + } catch (_) { } + return state +} class compressorSettings extends PluginSettingTab { plugin: compressorPlugin; diff --git a/package.json b/package.json index 6c75344..0688b88 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "compress", - "version": "1.0.0", + "version": "1.1.0", "description": "Make your files smaller with compression!", "main": "main.js", "scripts": { "dev": "node esbuild.config.mjs", - "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", + "build": "node archive/testchecks.js && tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", "version": "node version-bump.mjs && git add manifest.json versions.json" }, "keywords": [],