From e962fa40b955a47680c168f3b5ddb5d2516ac76d Mon Sep 17 00:00:00 2001 From: "Ludger A. Rinsche" Date: Sun, 10 Dec 2023 20:31:06 +0100 Subject: [PATCH 1/7] Added compressToCustom and decompressFromCustom function to use custom designed characters for compression. --- package.json | 1 + src/main.ts | 47 +++++++++++++++++++++++++++++++++++ tests/custom.test.js | 58 ++++++++++++++++++++++++++++++++++++++++++++ tests/testValues.js | 13 ++++++++++ 4 files changed, 119 insertions(+) create mode 100644 tests/custom.test.js diff --git a/package.json b/package.json index 53bf844..62d217b 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "test": "vitest src.main.test.js", "test:all": "vitest", "test:coverage": "vitest run --coverage", + "test:custom": "vitest custom.test.js", "lint": "eslint . --ext .ts" }, "devDependencies": { diff --git a/src/main.ts b/src/main.ts index 8436091..260215d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,6 +33,8 @@ export interface LZString { decompressFromUint8Array: (compressed: Uint8Array) => string | null; compressToEncodedURIComponent: (input: string) => string; decompressFromEncodedURIComponent: (input: string) => string | null; + compressToCustom: (uncompressed: string, dict: string) => string; + decompressFromCustom: (compressed: string, dict: string) => string | null; } export const LZString: LZString = (function () { @@ -147,6 +149,51 @@ export const LZString: LZString = (function () { }); }, + compressToCustom: function (uncompressed: string, dict: string): string { + const compressed: string = LZString.compress(uncompressed); + const charsPerUnicodeChar: number = Math.ceil(Math.log(65536) / Math.log(dict.length)); + let res: string = ""; + + for (let i = 0, TotalLen = compressed.length; i < TotalLen; i++) { + let current_value = compressed.charCodeAt(i); + + for (let j = charsPerUnicodeChar-1; j >= 0; j--) { + let selector = Math.floor(current_value / Math.pow(dict.length, j)); + current_value = current_value % Math.pow(dict.length, j); + res += dict.charAt(selector); + } + } + + return res; + }, + + decompressFromCustom: function (compressed: string, dict: string): string | null { + if (compressed == null) return ""; + if (compressed == "") return null; + if (dict.length < 2) return null; + + const charsPerUnicodeChar: number = Math.ceil(Math.log(65536) / Math.log(dict.length)); + + if (compressed.length % charsPerUnicodeChar != 0) return null; + + let res: string = ""; + let current_value; + let index; + + for (let i = 0, TotalLen = compressed.length; i < TotalLen; i=i+charsPerUnicodeChar) { + current_value = 0; + + for (let j = 0; j < charsPerUnicodeChar; j++) { + index = dict.indexOf(compressed[i+j]); + current_value = current_value + (index * Math.pow(dict.length, charsPerUnicodeChar - 1 - j)); + } + + res = res + String.fromCharCode(current_value); + } + + return LZString.decompress(res); + }, + compress: function (uncompressed: string): string { return LZString._compress(uncompressed, 16, function (a) { return f(a); diff --git a/tests/custom.test.js b/tests/custom.test.js new file mode 100644 index 0000000..0668efa --- /dev/null +++ b/tests/custom.test.js @@ -0,0 +1,58 @@ +import { test, expect } from "vitest"; +import { + test_hw, + test_repeat, + test_tattooSource, + test_longString, + test_complicated, +} from "tests/testValues.js"; +import { LZString } from "../src/main"; + +const hex = "0123456789ABCDEF"; +const base62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + +test(`Custom : Hello World - something happens`, () => { + expect(LZString.compressToCustom(test_hw, "0123456789")).not.toEqual(test_hw); +}); + + + +test(`Custom : Hello World - hex : equals decompression of its compression`, () => { + expect(LZString.decompressFromCustom(LZString.compressToCustom(test_hw, hex), hex)).toEqual(test_hw); +}); + +test(`Custom : repeat - hex : equals decompression of its compression`, () => { + expect(LZString.decompressFromCustom(LZString.compressToCustom(test_repeat, hex), hex)).toEqual(test_repeat); +}); + +test(`Custom : tattooSource - hex : equals decompression of its compression`, () => { + expect(LZString.decompressFromCustom(LZString.compressToCustom(test_tattooSource, hex), hex)).toEqual(test_tattooSource); +}); + +test(`Custom : complicated - hex : equals decompression of its compression`, () => { + expect(LZString.decompressFromCustom(LZString.compressToCustom(test_complicated, hex), hex)).toEqual(test_complicated); +}); + + + +test(`Custom : Hello World - base62 : equals decompression of its compression`, () => { + expect(LZString.decompressFromCustom(LZString.compressToCustom(test_hw, base62), base62)).toEqual(test_hw); +}); + +test(`Custom : repeat - base62 : equals decompression of its compression`, () => { + expect(LZString.decompressFromCustom(LZString.compressToCustom(test_repeat, base62), base62)).toEqual(test_repeat); +}); + +test(`Custom : tattooSource - base62 : equals decompression of its compression`, () => { + expect(LZString.decompressFromCustom(LZString.compressToCustom(test_tattooSource, base62), base62)).toEqual(test_tattooSource); +}); + +test(`Custom : longString - base62 : equals decompression of its compression`, () => { + let str = test_longString(); + expect(LZString.decompressFromCustom(LZString.compressToCustom(str, base62), base62)).toEqual(str); +}); + +test(`Custom : complicated - base62 : equals decompression of its compression`, () => { + expect(LZString.decompressFromCustom(LZString.compressToCustom(test_complicated, base62), base62)).toEqual(test_complicated); +}); diff --git a/tests/testValues.js b/tests/testValues.js index ff76f16..033c382 100644 --- a/tests/testValues.js +++ b/tests/testValues.js @@ -55,6 +55,19 @@ export const test_tattooUint8Array = new Uint8Array([ export const test_tattooUTF16 = "\u0462\u5C33\u414C\u0780\u7320\u1025\u6063\u0230\u3DBB\u51A0\u3496\u40F6\u3C26\u3A05K\u00C6\u01AC\u0870\u04F4\u7AA8\u00D0\u5731\u7DC5\u6D24\u0441\u25AE\u0934\u1E20\u5B71\u1070\u6CE0\u2930\u0093\u22A4\u2177\u1863\u152AV\u4D44\u54B3\u37F3\u4024\u2534\u456C\u0D3C\u7344\u18D2\u4702\u45C0\u0393\u36A4\u60B5\u486C\u5241\u282C\u4648\u2890\u1059\u3DA7\u55EA\u0FA0\u03C3\u4020\u555D\u2706\u4B8B\u2DCE\u492C\u0620\u0517\u31C2\u44F8\u6820\u3336\u0481\u1DF3\u6024\u3363\u5284\u01E8\u24BA\u4CF1\u15BC\u0A2A\u5B4B\u4749@\u7312\u2C61\u74D6\u0164\u00E1\u402E\u7606\u32B2\u08A9\u48F9\u394E\u6E25\u147C\u5F67\u2456\u4337\u5958\u5051\u78B4\u1D7C\u149A\u6DFA\u37E5\u4A8F\u1170\u1890\u2728\u1124\u1CD3\u26E9\u137B\u028C\u39C0\u31E0\u7D86\u1A28\u1F0D\u4022\u5440\u1738\u0F90\u218A\u1220\u0844\u7970\u7020\u0C7F\u2359\u20F6\u28B8\u43A1\u564E\u26B2\u6430\u7D08\u1CA2\u03F2\u3490\u39B0\u1364\u3C61\u28ED\u0323\u7044\u397B\u1661\u40D6\u1F36\u04FA\u1236\u15A6\u6758\u29FD\u35A5\u63A0\u64C6\u3430\u622B\u430C\u2F3F\u1249\u45B7\u3A2D\u01A8\u0092\u0A48\u6103\u1859\u14D9\u6907\u7256\u2635\u08C2\u1060\u5EB8\u5741\u498E\u3FB1\u00F3\u4029\u183E\u2520\u2020\u5A41\u4482\u5545\u1CF4\u57E0\u63A4\u2271\u0223\u01A0\u2856\u0CC6\u6054\u4D69\u55C6\u5931\u0B37\u16F2\u0408\u1704\u1B8F\u02E7\u1B8A\u4DAE\u1899\u4571\u0644\u3021\u6ACC\u08B7\u2A8B\u52A2\u2F31\u0361\u60BA\u1239\u2321\u6E05\u2590\u61B7\u2EA2\u73BF\u2700\u4467\u2152\u34E9\u7F0C\u0520\u18CB\u406A\u2E2C\u2A41\u7439\u1628\u38CA\u3497\u2D2C\u0D8C\u5897\u094E\u5DE2\u4634\u0D7F\u4F2C\u7D72\u0327\u63C1\u4040\u3C27\u48E5\u50D2\u1426\u570B\u3CFA\u366F\u4B80\u2474\u24F0\u5049\u6DAC\u734E\u00C0\u0A25\u3521\u06E3\u6CBE\u1129\u00A1\u684C\u6DBA\u5739\u02F1\u508E\u4D18\u2836\u28B9\u208C\u4872\u3676\u4622\u4C82\u2213\u734D\u03C2\u7042\u0679\u3B30\u0892\u1453\u63F9\u583F\u0DAB\u3A98\u1D20\u0A2A\u6E40\u0465\u0330i\u08A0\u28EC\u1807\u018B\u32A0\u6134\u26EC\u34F0\u06A4\u2068\u2202\u5C8A\u2834\u6283\u260C\u0A0E\u2C2C\u5CF8\u1D2F\u4240\u7320\u21AA\u283E\u19D4\u0B34\u2380\u6921\u22B0\u1537\u6058\u7F6C\u52F4\u1E2D\u68C9\u0829\u51D7\u0D22\u124D\u0AEB\u7118\u1DCE\u2348\u69AE\u40D2\u1464\u0020\u0020"; +export const test_complicated = `Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. +Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. +Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. +At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. +Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus. +Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. +Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. +Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. +Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo +Alle Unicode-Symbole und ihre Codes auf einer Seite, 𐎰, 103B0, 𐎱, 103B1, 𐎲, 103B2, 𐎳, 103B3, 𐎴, 103B4, 𐎵, 103B5, 𐎶, 103B6, 𐎷, 103B7, 𐎸, 103B8, 𐎹, 103B9, 𐎺, 103BA, 𐎻, 103BB, 𐎼, 103BC, 𐎽, 103BD, 𐎾, 103BE, 𐎿, 103BF, 𐏀, 103C0, 𐏁, 103C1, 𐏂, 103C2, 𐏃, 103C3, 103C4, 103C5, 103C6, 103C7, 𐏈, 103C8, 𐏉, 103C9, 𐏊, 103CA, 𐏋, 103CB, 𐏌, 103CC, 𐏍, 103CD, 𐏎, 103CE, 𐏏`; + export function test_allUtf16() { const testValue = []; for (let i = 32; i < 127; i++) { From 325d42e812ebc1fa11e39cb801503eba9c21706e Mon Sep 17 00:00:00 2001 From: "Ludger A. Rinsche" Date: Sat, 20 Jan 2024 22:59:50 +0100 Subject: [PATCH 2/7] Redone compressToCustom/decompressFromCustom as split file version. --- package.json | 1 + src/custom/compressToCustom.ts | 19 +++++++++++++++++++ src/custom/decompressFromCustom.ts | 28 ++++++++++++++++++++++++++++ src/custom/index.ts | 2 ++ src/index.ts | 4 ++++ tests/custom.test.js | 4 ++-- 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/custom/compressToCustom.ts create mode 100644 src/custom/decompressFromCustom.ts create mode 100644 src/custom/index.ts diff --git a/package.json b/package.json index 0bbed65..dedd249 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "start": "vite build --watch", "test": "[ -f ./dist/index.js ] || npm run build && vitest", "test:coverage": "vitest run src.main.test.ts --coverage", + "test:custom": "vitest custom.test.js", "lint": "eslint ." }, "devDependencies": { diff --git a/src/custom/compressToCustom.ts b/src/custom/compressToCustom.ts new file mode 100644 index 0000000..afb2805 --- /dev/null +++ b/src/custom/compressToCustom.ts @@ -0,0 +1,19 @@ +import { compress } from "../stock/compress"; + +export function compressToCustom (uncompressed: string, dict: string): string { + const compressed: string = compress(uncompressed); + const charsPerUnicodeChar: number = Math.ceil(Math.log(65536) / Math.log(dict.length)); + let res: string = ""; + + for (let i = 0, TotalLen = compressed.length; i < TotalLen; i++) { + let current_value = compressed.charCodeAt(i); + + for (let j = charsPerUnicodeChar-1; j >= 0; j--) { + const selector = Math.floor(current_value / Math.pow(dict.length, j)); + current_value = current_value % Math.pow(dict.length, j); + res += dict.charAt(selector); + } + } + + return res; +} \ No newline at end of file diff --git a/src/custom/decompressFromCustom.ts b/src/custom/decompressFromCustom.ts new file mode 100644 index 0000000..8ae477c --- /dev/null +++ b/src/custom/decompressFromCustom.ts @@ -0,0 +1,28 @@ +import { decompress } from "../stock/decompress"; + +export function decompressFromCustom (compressed: string, dict: string): string | null { + if (compressed == null) return ""; + if (compressed == "") return null; + if (dict.length < 2) return null; + + const charsPerUnicodeChar: number = Math.ceil(Math.log(65536) / Math.log(dict.length)); + + if (compressed.length % charsPerUnicodeChar != 0) return null; + + let res: string = ""; + let current_value; + let index; + + for (let i = 0, TotalLen = compressed.length; i < TotalLen; i=i+charsPerUnicodeChar) { + current_value = 0; + + for (let j = 0; j < charsPerUnicodeChar; j++) { + index = dict.indexOf(compressed[i+j]); + current_value = current_value + (index * Math.pow(dict.length, charsPerUnicodeChar - 1 - j)); + } + + res = res + String.fromCharCode(current_value); + } + + return decompress(res); +} \ No newline at end of file diff --git a/src/custom/index.ts b/src/custom/index.ts new file mode 100644 index 0000000..e1e2cbf --- /dev/null +++ b/src/custom/index.ts @@ -0,0 +1,2 @@ +export { compressToCustom } from "./compressToCustom"; +export { decompressFromCustom } from "./decompressFromCustom"; diff --git a/src/index.ts b/src/index.ts index 4a09bd7..846235c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ import { compressToEncodedURIComponent, decompressFromEncodedURIComponent } from import { compress, decompress } from "./stock"; import { compressToUint8Array, decompressFromUint8Array } from "./Uint8Array"; import { compressToUTF16, decompressFromUTF16 } from "./UTF16"; +import { compressToCustom, decompressFromCustom } from "./custom"; export default { _compress, @@ -34,4 +35,7 @@ export default { compressToUTF16, decompressFromUTF16, + + compressToCustom, + decompressFromCustom, }; diff --git a/tests/custom.test.js b/tests/custom.test.js index 0668efa..53161c4 100644 --- a/tests/custom.test.js +++ b/tests/custom.test.js @@ -5,8 +5,8 @@ import { test_tattooSource, test_longString, test_complicated, -} from "tests/testValues.js"; -import { LZString } from "../src/main"; +} from "./testValues"; +import LZString from "../src"; const hex = "0123456789ABCDEF"; const base62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; From 73bcd2c5e61914119cd489bde8e88e1328bb31dc Mon Sep 17 00:00:00 2001 From: "Ludger A. Rinsche" Date: Sat, 20 Jan 2024 23:31:53 +0100 Subject: [PATCH 3/7] Moved tests to src\custom. --- package.json | 1 - src/custom/custom.test.ts | 59 +++++++++++++++++++++++++++++++++++++++ tests/custom.test.js | 58 -------------------------------------- tests/testValues.ts | 14 ++++++++++ 4 files changed, 73 insertions(+), 59 deletions(-) create mode 100644 src/custom/custom.test.ts delete mode 100644 tests/custom.test.js diff --git a/package.json b/package.json index dedd249..0bbed65 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ "start": "vite build --watch", "test": "[ -f ./dist/index.js ] || npm run build && vitest", "test:coverage": "vitest run src.main.test.ts --coverage", - "test:custom": "vitest custom.test.js", "lint": "eslint ." }, "devDependencies": { diff --git a/src/custom/custom.test.ts b/src/custom/custom.test.ts new file mode 100644 index 0000000..01ab563 --- /dev/null +++ b/src/custom/custom.test.ts @@ -0,0 +1,59 @@ +import { describe, expect, test } from "vitest"; +import { compressToCustom, decompressFromCustom } from "."; +import { test_longString_fn } from "../__tests__/testFunctions"; +import { + test_hw, + test_repeat, + test_tattooSource, + test_complicated, +} from "../../tests/testValues"; + +describe("custom", () => { + const hex = "0123456789ABCDEF"; + const base62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + test(`Custom : Hello World - something happens`, () => { + expect(compressToCustom(test_hw, "0123456789")).not.toEqual(test_hw); + }); + + + + test(`Custom : Hello World - hex : equals decompression of its compression`, () => { + expect(decompressFromCustom(compressToCustom(test_hw, hex), hex)).toEqual(test_hw); + }); + + test(`Custom : repeat - hex : equals decompression of its compression`, () => { + expect(decompressFromCustom(compressToCustom(test_repeat, hex), hex)).toEqual(test_repeat); + }); + + test(`Custom : tattooSource - hex : equals decompression of its compression`, () => { + expect(decompressFromCustom(compressToCustom(test_tattooSource, hex), hex)).toEqual(test_tattooSource); + }); + + test(`Custom : complicated - hex : equals decompression of its compression`, () => { + expect(decompressFromCustom(compressToCustom(test_complicated, hex), hex)).toEqual(test_complicated); + }); + + + + test(`Custom : Hello World - base62 : equals decompression of its compression`, () => { + expect(decompressFromCustom(compressToCustom(test_hw, base62), base62)).toEqual(test_hw); + }); + + test(`Custom : repeat - base62 : equals decompression of its compression`, () => { + expect(decompressFromCustom(compressToCustom(test_repeat, base62), base62)).toEqual(test_repeat); + }); + + test(`Custom : tattooSource - base62 : equals decompression of its compression`, () => { + expect(decompressFromCustom(compressToCustom(test_tattooSource, base62), base62)).toEqual(test_tattooSource); + }); + + test(`Custom : longString - base62 : equals decompression of its compression`, () => { + const str = test_longString_fn() + expect(decompressFromCustom(compressToCustom(str, base62), base62)).toEqual(str); + }); + + test(`Custom : complicated - base62 : equals decompression of its compression`, () => { + expect(decompressFromCustom(compressToCustom(test_complicated, base62), base62)).toEqual(test_complicated); + }); +}); diff --git a/tests/custom.test.js b/tests/custom.test.js deleted file mode 100644 index 53161c4..0000000 --- a/tests/custom.test.js +++ /dev/null @@ -1,58 +0,0 @@ -import { test, expect } from "vitest"; -import { - test_hw, - test_repeat, - test_tattooSource, - test_longString, - test_complicated, -} from "./testValues"; -import LZString from "../src"; - -const hex = "0123456789ABCDEF"; -const base62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - - -test(`Custom : Hello World - something happens`, () => { - expect(LZString.compressToCustom(test_hw, "0123456789")).not.toEqual(test_hw); -}); - - - -test(`Custom : Hello World - hex : equals decompression of its compression`, () => { - expect(LZString.decompressFromCustom(LZString.compressToCustom(test_hw, hex), hex)).toEqual(test_hw); -}); - -test(`Custom : repeat - hex : equals decompression of its compression`, () => { - expect(LZString.decompressFromCustom(LZString.compressToCustom(test_repeat, hex), hex)).toEqual(test_repeat); -}); - -test(`Custom : tattooSource - hex : equals decompression of its compression`, () => { - expect(LZString.decompressFromCustom(LZString.compressToCustom(test_tattooSource, hex), hex)).toEqual(test_tattooSource); -}); - -test(`Custom : complicated - hex : equals decompression of its compression`, () => { - expect(LZString.decompressFromCustom(LZString.compressToCustom(test_complicated, hex), hex)).toEqual(test_complicated); -}); - - - -test(`Custom : Hello World - base62 : equals decompression of its compression`, () => { - expect(LZString.decompressFromCustom(LZString.compressToCustom(test_hw, base62), base62)).toEqual(test_hw); -}); - -test(`Custom : repeat - base62 : equals decompression of its compression`, () => { - expect(LZString.decompressFromCustom(LZString.compressToCustom(test_repeat, base62), base62)).toEqual(test_repeat); -}); - -test(`Custom : tattooSource - base62 : equals decompression of its compression`, () => { - expect(LZString.decompressFromCustom(LZString.compressToCustom(test_tattooSource, base62), base62)).toEqual(test_tattooSource); -}); - -test(`Custom : longString - base62 : equals decompression of its compression`, () => { - let str = test_longString(); - expect(LZString.decompressFromCustom(LZString.compressToCustom(str, base62), base62)).toEqual(str); -}); - -test(`Custom : complicated - base62 : equals decompression of its compression`, () => { - expect(LZString.decompressFromCustom(LZString.compressToCustom(test_complicated, base62), base62)).toEqual(test_complicated); -}); diff --git a/tests/testValues.ts b/tests/testValues.ts index 6d7cadf..e6821dc 100644 --- a/tests/testValues.ts +++ b/tests/testValues.ts @@ -112,3 +112,17 @@ export const test_tattooUint8Array = new Uint8Array([ /** Known output for UTF16 compression */ export const test_tattooUTF16 = "\u0462\u5C33\u414C\u0780\u7320\u1025\u6063\u0230\u3DBB\u51A0\u3496\u40F6\u3C26\u3A05K\u00C6\u01AC\u0870\u04F4\u7AA8\u00D0\u5731\u7DC5\u6D24\u0441\u25AE\u0934\u1E20\u5B71\u1070\u6CE0\u2930\u0093\u22A4\u2177\u1863\u152AV\u4D44\u54B3\u37F3\u4024\u2534\u456C\u0D3C\u7344\u18D2\u4702\u45C0\u0393\u36A4\u60B5\u486C\u5241\u282C\u4648\u2890\u1059\u3DA7\u55EA\u0FA0\u03C3\u4020\u555D\u2706\u4B8B\u2DCE\u492C\u0620\u0517\u31C2\u44F8\u6820\u3336\u0481\u1DF3\u6024\u3363\u5284\u01E8\u24BA\u4CF1\u15BC\u0A2A\u5B4B\u4749@\u7312\u2C61\u74D6\u0164\u00E1\u402E\u7606\u32B2\u08A9\u48F9\u394E\u6E25\u147C\u5F67\u2456\u4337\u5958\u5051\u78B4\u1D7C\u149A\u6DFA\u37E5\u4A8F\u1170\u1890\u2728\u1124\u1CD3\u26E9\u137B\u028C\u39C0\u31E0\u7D86\u1A28\u1F0D\u4022\u5440\u1738\u0F90\u218A\u1220\u0844\u7970\u7020\u0C7F\u2359\u20F6\u28B8\u43A1\u564E\u26B2\u6430\u7D08\u1CA2\u03F2\u3490\u39B0\u1364\u3C61\u28ED\u0323\u7044\u397B\u1661\u40D6\u1F36\u04FA\u1236\u15A6\u6758\u29FD\u35A5\u63A0\u64C6\u3430\u622B\u430C\u2F3F\u1249\u45B7\u3A2D\u01A8\u0092\u0A48\u6103\u1859\u14D9\u6907\u7256\u2635\u08C2\u1060\u5EB8\u5741\u498E\u3FB1\u00F3\u4029\u183E\u2520\u2020\u5A41\u4482\u5545\u1CF4\u57E0\u63A4\u2271\u0223\u01A0\u2856\u0CC6\u6054\u4D69\u55C6\u5931\u0B37\u16F2\u0408\u1704\u1B8F\u02E7\u1B8A\u4DAE\u1899\u4571\u0644\u3021\u6ACC\u08B7\u2A8B\u52A2\u2F31\u0361\u60BA\u1239\u2321\u6E05\u2590\u61B7\u2EA2\u73BF\u2700\u4467\u2152\u34E9\u7F0C\u0520\u18CB\u406A\u2E2C\u2A41\u7439\u1628\u38CA\u3497\u2D2C\u0D8C\u5897\u094E\u5DE2\u4634\u0D7F\u4F2C\u7D72\u0327\u63C1\u4040\u3C27\u48E5\u50D2\u1426\u570B\u3CFA\u366F\u4B80\u2474\u24F0\u5049\u6DAC\u734E\u00C0\u0A25\u3521\u06E3\u6CBE\u1129\u00A1\u684C\u6DBA\u5739\u02F1\u508E\u4D18\u2836\u28B9\u208C\u4872\u3676\u4622\u4C82\u2213\u734D\u03C2\u7042\u0679\u3B30\u0892\u1453\u63F9\u583F\u0DAB\u3A98\u1D20\u0A2A\u6E40\u0465\u0330i\u08A0\u28EC\u1807\u018B\u32A0\u6134\u26EC\u34F0\u06A4\u2068\u2202\u5C8A\u2834\u6283\u260C\u0A0E\u2C2C\u5CF8\u1D2F\u4240\u7320\u21AA\u283E\u19D4\u0B34\u2380\u6921\u22B0\u1537\u6058\u7F6C\u52F4\u1E2D\u68C9\u0829\u51D7\u0D22\u124D\u0AEB\u7118\u1DCE\u2348\u69AE\u40D2\u1464\u0020\u0020"; + +/** A longer text including very unusual symbols */ +export const test_complicated = `Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. + Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. + Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. + At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. + Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus. + Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. + Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. + Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo + Alle Unicode-Symbole und ihre Codes auf einer Seite, 𐎰, 103B0, 𐎱, 103B1, 𐎲, 103B2, 𐎳, 103B3, 𐎴, 103B4, 𐎵, 103B5, 𐎶, 103B6, 𐎷, 103B7, 𐎸, 103B8, 𐎹, 103B9, 𐎺, 103BA, 𐎻, 103BB, 𐎼, 103BC, 𐎽, 103BD, 𐎾, 103BE, 𐎿, 103BF, 𐏀, 103C0, 𐏁, 103C1, 𐏂, 103C2, 𐏃, 103C3, 103C4, 103C5, 103C6, 103C7, 𐏈, 103C8, 𐏉, 103C9, 𐏊, 103CA, 𐏋, 103CB, 𐏌, 103CC, 𐏍, 103CD, 𐏎, 103CE, 𐏏`; From 2fd98ca099a680817b8979229704ab22edb495ae Mon Sep 17 00:00:00 2001 From: "Ludger A. Rinsche" Date: Mon, 22 Jan 2024 18:09:47 +0100 Subject: [PATCH 4/7] Removed special chars from long text --- tests/testValues.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/testValues.ts b/tests/testValues.ts index b9a19a5..e6116d4 100644 --- a/tests/testValues.ts +++ b/tests/testValues.ts @@ -119,7 +119,7 @@ export const test_tattooUint8Array = new Uint8Array([ export const test_tattooUTF16 = "\u0462\u5C33\u414C\u0780\u7320\u1025\u6063\u0230\u3DBB\u51A0\u3496\u40F6\u3C26\u3A05K\u00C6\u01AC\u0870\u04F4\u7AA8\u00D0\u5731\u7DC5\u6D24\u0441\u25AE\u0934\u1E20\u5B71\u1070\u6CE0\u2930\u0093\u22A4\u2177\u1863\u152AV\u4D44\u54B3\u37F3\u4024\u2534\u456C\u0D3C\u7344\u18D2\u4702\u45C0\u0393\u36A4\u60B5\u486C\u5241\u282C\u4648\u2890\u1059\u3DA7\u55EA\u0FA0\u03C3\u4020\u555D\u2706\u4B8B\u2DCE\u492C\u0620\u0517\u31C2\u44F8\u6820\u3336\u0481\u1DF3\u6024\u3363\u5284\u01E8\u24BA\u4CF1\u15BC\u0A2A\u5B4B\u4749@\u7312\u2C61\u74D6\u0164\u00E1\u402E\u7606\u32B2\u08A9\u48F9\u394E\u6E25\u147C\u5F67\u2456\u4337\u5958\u5051\u78B4\u1D7C\u149A\u6DFA\u37E5\u4A8F\u1170\u1890\u2728\u1124\u1CD3\u26E9\u137B\u028C\u39C0\u31E0\u7D86\u1A28\u1F0D\u4022\u5440\u1738\u0F90\u218A\u1220\u0844\u7970\u7020\u0C7F\u2359\u20F6\u28B8\u43A1\u564E\u26B2\u6430\u7D08\u1CA2\u03F2\u3490\u39B0\u1364\u3C61\u28ED\u0323\u7044\u397B\u1661\u40D6\u1F36\u04FA\u1236\u15A6\u6758\u29FD\u35A5\u63A0\u64C6\u3430\u622B\u430C\u2F3F\u1249\u45B7\u3A2D\u01A8\u0092\u0A48\u6103\u1859\u14D9\u6907\u7256\u2635\u08C2\u1060\u5EB8\u5741\u498E\u3FB1\u00F3\u4029\u183E\u2520\u2020\u5A41\u4482\u5545\u1CF4\u57E0\u63A4\u2271\u0223\u01A0\u2856\u0CC6\u6054\u4D69\u55C6\u5931\u0B37\u16F2\u0408\u1704\u1B8F\u02E7\u1B8A\u4DAE\u1899\u4571\u0644\u3021\u6ACC\u08B7\u2A8B\u52A2\u2F31\u0361\u60BA\u1239\u2321\u6E05\u2590\u61B7\u2EA2\u73BF\u2700\u4467\u2152\u34E9\u7F0C\u0520\u18CB\u406A\u2E2C\u2A41\u7439\u1628\u38CA\u3497\u2D2C\u0D8C\u5897\u094E\u5DE2\u4634\u0D7F\u4F2C\u7D72\u0327\u63C1\u4040\u3C27\u48E5\u50D2\u1426\u570B\u3CFA\u366F\u4B80\u2474\u24F0\u5049\u6DAC\u734E\u00C0\u0A25\u3521\u06E3\u6CBE\u1129\u00A1\u684C\u6DBA\u5739\u02F1\u508E\u4D18\u2836\u28B9\u208C\u4872\u3676\u4622\u4C82\u2213\u734D\u03C2\u7042\u0679\u3B30\u0892\u1453\u63F9\u583F\u0DAB\u3A98\u1D20\u0A2A\u6E40\u0465\u0330i\u08A0\u28EC\u1807\u018B\u32A0\u6134\u26EC\u34F0\u06A4\u2068\u2202\u5C8A\u2834\u6283\u260C\u0A0E\u2C2C\u5CF8\u1D2F\u4240\u7320\u21AA\u283E\u19D4\u0B34\u2380\u6921\u22B0\u1537\u6058\u7F6C\u52F4\u1E2D\u68C9\u0829\u51D7\u0D22\u124D\u0AEB\u7118\u1DCE\u2348\u69AE\u40D2\u1464\u0020\u0020"; -/** A longer text including very unusual symbols */ +/** A longer lorem ipsum text */ export const test_complicated = `Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. @@ -130,5 +130,4 @@ export const test_complicated = `Lorem ipsum dolor sit amet, consetetur sadipsci Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. - Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo - Alle Unicode-Symbole und ihre Codes auf einer Seite, 𐎰, 103B0, 𐎱, 103B1, 𐎲, 103B2, 𐎳, 103B3, 𐎴, 103B4, 𐎵, 103B5, 𐎶, 103B6, 𐎷, 103B7, 𐎸, 103B8, 𐎹, 103B9, 𐎺, 103BA, 𐎻, 103BB, 𐎼, 103BC, 𐎽, 103BD, 𐎾, 103BE, 𐎿, 103BF, 𐏀, 103C0, 𐏁, 103C1, 𐏂, 103C2, 𐏃, 103C3, 103C4, 103C5, 103C6, 103C7, 𐏈, 103C8, 𐏉, 103C9, 𐏊, 103CA, 𐏋, 103CB, 𐏌, 103CC, 𐏍, 103CD, 𐏎, 103CE, 𐏏`; + Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo.`; From 80bc5a7050a3bd7abd0eb7931cc97e9be951ca05 Mon Sep 17 00:00:00 2001 From: "Ludger A. Rinsche" Date: Mon, 22 Jan 2024 18:42:44 +0100 Subject: [PATCH 5/7] Added license header. --- src/custom/compressToCustom.ts | 6 ++++++ src/custom/custom.test.ts | 6 ++++++ src/custom/decompressFromCustom.ts | 6 ++++++ src/custom/index.ts | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/src/custom/compressToCustom.ts b/src/custom/compressToCustom.ts index afb2805..add7f21 100644 --- a/src/custom/compressToCustom.ts +++ b/src/custom/compressToCustom.ts @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2013 Pieroxy + * + * SPDX-License-Identifier: MIT + */ + import { compress } from "../stock/compress"; export function compressToCustom (uncompressed: string, dict: string): string { diff --git a/src/custom/custom.test.ts b/src/custom/custom.test.ts index 01ab563..1c325f7 100644 --- a/src/custom/custom.test.ts +++ b/src/custom/custom.test.ts @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2013 Pieroxy + * + * SPDX-License-Identifier: MIT + */ + import { describe, expect, test } from "vitest"; import { compressToCustom, decompressFromCustom } from "."; import { test_longString_fn } from "../__tests__/testFunctions"; diff --git a/src/custom/decompressFromCustom.ts b/src/custom/decompressFromCustom.ts index 8ae477c..34c2ba4 100644 --- a/src/custom/decompressFromCustom.ts +++ b/src/custom/decompressFromCustom.ts @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2013 Pieroxy + * + * SPDX-License-Identifier: MIT + */ + import { decompress } from "../stock/decompress"; export function decompressFromCustom (compressed: string, dict: string): string | null { diff --git a/src/custom/index.ts b/src/custom/index.ts index e1e2cbf..376d38d 100644 --- a/src/custom/index.ts +++ b/src/custom/index.ts @@ -1,2 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2013 Pieroxy + * + * SPDX-License-Identifier: MIT + */ + export { compressToCustom } from "./compressToCustom"; export { decompressFromCustom } from "./decompressFromCustom"; From 391b7322a7d4a34c51ae31ce02acce6ea4cfa3dd Mon Sep 17 00:00:00 2001 From: "Ludger A. Rinsche" Date: Mon, 22 Jan 2024 21:16:03 +0100 Subject: [PATCH 6/7] Aligned test logic an added correct typing for compressToCustom. --- src/custom/compressToCustom.ts | 4 +- src/custom/custom.test.ts | 74 ++++++++++------------------------ 2 files changed, 25 insertions(+), 53 deletions(-) diff --git a/src/custom/compressToCustom.ts b/src/custom/compressToCustom.ts index add7f21..f33fbe3 100644 --- a/src/custom/compressToCustom.ts +++ b/src/custom/compressToCustom.ts @@ -6,7 +6,9 @@ import { compress } from "../stock/compress"; -export function compressToCustom (uncompressed: string, dict: string): string { +export function compressToCustom (uncompressed: string | null, dict: string): string { + if (uncompressed == null) return ""; + const compressed: string = compress(uncompressed); const charsPerUnicodeChar: number = Math.ceil(Math.log(65536) / Math.log(dict.length)); let res: string = ""; diff --git a/src/custom/custom.test.ts b/src/custom/custom.test.ts index 1c325f7..103cfce 100644 --- a/src/custom/custom.test.ts +++ b/src/custom/custom.test.ts @@ -4,62 +4,32 @@ * SPDX-License-Identifier: MIT */ -import { describe, expect, test } from "vitest"; +import { describe } from "vitest"; import { compressToCustom, decompressFromCustom } from "."; -import { test_longString_fn } from "../__tests__/testFunctions"; -import { - test_hw, - test_repeat, - test_tattooSource, - test_complicated, -} from "../../tests/testValues"; +import { runTestSet } from "../__tests__/testFunctions"; describe("custom", () => { - const hex = "0123456789ABCDEF"; - const base62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - - test(`Custom : Hello World - something happens`, () => { - expect(compressToCustom(test_hw, "0123456789")).not.toEqual(test_hw); - }); - - - - test(`Custom : Hello World - hex : equals decompression of its compression`, () => { - expect(decompressFromCustom(compressToCustom(test_hw, hex), hex)).toEqual(test_hw); - }); - - test(`Custom : repeat - hex : equals decompression of its compression`, () => { - expect(decompressFromCustom(compressToCustom(test_repeat, hex), hex)).toEqual(test_repeat); - }); - - test(`Custom : tattooSource - hex : equals decompression of its compression`, () => { - expect(decompressFromCustom(compressToCustom(test_tattooSource, hex), hex)).toEqual(test_tattooSource); - }); - - test(`Custom : complicated - hex : equals decompression of its compression`, () => { - expect(decompressFromCustom(compressToCustom(test_complicated, hex), hex)).toEqual(test_complicated); - }); - - - - test(`Custom : Hello World - base62 : equals decompression of its compression`, () => { - expect(decompressFromCustom(compressToCustom(test_hw, base62), base62)).toEqual(test_hw); + describe("hex", () => { + const hex = "0123456789ABCDEF"; + const compress = (input: string | null) => compressToCustom(input, hex); + const decompress = (input: string | null) => decompressFromCustom(input, hex); + + runTestSet(compress, decompress, ""); }); - - test(`Custom : repeat - base62 : equals decompression of its compression`, () => { - expect(decompressFromCustom(compressToCustom(test_repeat, base62), base62)).toEqual(test_repeat); - }); - - test(`Custom : tattooSource - base62 : equals decompression of its compression`, () => { - expect(decompressFromCustom(compressToCustom(test_tattooSource, base62), base62)).toEqual(test_tattooSource); - }); - - test(`Custom : longString - base62 : equals decompression of its compression`, () => { - const str = test_longString_fn() - expect(decompressFromCustom(compressToCustom(str, base62), base62)).toEqual(str); + + describe("23 letter heterogram", () => { + const heterogram = "BlockyDwarfZingsTheJump"; + const compress = (input: string | null) => compressToCustom(input, heterogram); + const decompress = (input: string | null) => decompressFromCustom(input, heterogram); + + runTestSet(compress, decompress, ""); }); - - test(`Custom : complicated - base62 : equals decompression of its compression`, () => { - expect(decompressFromCustom(compressToCustom(test_complicated, base62), base62)).toEqual(test_complicated); + + describe("base62", () => { + const base62 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + const compress = (input: string | null) => compressToCustom(input, base62); + const decompress = (input: string | null) => decompressFromCustom(input, base62); + + runTestSet(compress, decompress, ""); }); }); From 8018fa9605ee2ff2ee48e5a003696b3961cd8380 Mon Sep 17 00:00:00 2001 From: "Ludger A. Rinsche" Date: Mon, 22 Jan 2024 21:27:26 +0100 Subject: [PATCH 7/7] Added missing typing for input in decompressFromCustom. --- src/custom/decompressFromCustom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/custom/decompressFromCustom.ts b/src/custom/decompressFromCustom.ts index 34c2ba4..66f2d28 100644 --- a/src/custom/decompressFromCustom.ts +++ b/src/custom/decompressFromCustom.ts @@ -6,7 +6,7 @@ import { decompress } from "../stock/decompress"; -export function decompressFromCustom (compressed: string, dict: string): string | null { +export function decompressFromCustom (compressed: string | null, dict: string): string | null { if (compressed == null) return ""; if (compressed == "") return null; if (dict.length < 2) return null;