-
Notifications
You must be signed in to change notification settings - Fork 570
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
Issues and v2 work updates #189
Open
karnthis
wants to merge
15
commits into
pieroxy:master
Choose a base branch
from
karnthis:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ce476fe
Merge pull request #1 from pieroxy/master
karnthis a1e8dd0
Chore: address invalid Base64 returns (/pieroxy/lz-string/issues/184)
karnthis aec06d2
Chore: address invalid Base64 encoding (/pieroxy/lz-string/issues/110)
karnthis 32e6ed1
Chore: implements Base64URL suggestion (/pieroxy/lz-string/pull/127)
karnthis b8f6898
removing browser-specific elements from utils
karnthis c0eeb08
tests pt.1 - splitting into reusable library
karnthis e6c2537
tests pt.2 - breaking out test sets to allow for variations
karnthis 4b030c6
tests pt.3 - started creating more specific tests. all tests now pass
karnthis 42d7a24
tests pt.4 - safer test running
karnthis 6e33f3a
Merge branch master 'pieroxy/master' into resync
karnthis bde410d
refactored updates
karnthis 89a6f53
formatting
karnthis 286ff3b
pr suggestion: reorganize new functions
karnthis 9d2a326
pr suggestion: refactor function names
karnthis 229d9fa
pr suggestion: refactor test logic
karnthis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { _compress } from "../_compress"; | ||
import { _decompress } from "../_decompress"; | ||
import { getBaseValue } from "../getBaseValue"; | ||
|
||
const keyStrBase64URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | ||
|
||
export function compressToBase64URL(input: string): string { | ||
if (!input) { | ||
return ""; | ||
} | ||
return _compress(input, 6, (a) => keyStrBase64URL.charAt(a)); | ||
} | ||
|
||
export function decompressFromBase64URL(input: string): string { | ||
if (!input) { | ||
return ""; | ||
} | ||
const res = _decompress(input.length, 32, (index) => getBaseValue(keyStrBase64URL, input.charAt(index))); | ||
return res || ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { _compress } from "../_compress"; | ||
import keyStrBase64 from "./keyStrBase64"; | ||
import { _decompress } from "../_decompress"; | ||
import { getBaseValue } from "../getBaseValue"; | ||
|
||
export function compressToBetterBase64(input: string): string { | ||
if (!input) { | ||
return ""; | ||
} | ||
const res = _compress(input, 6, (a) => keyStrBase64.charAt(a)); | ||
|
||
// To produce valid Base64 | ||
switch (res.length % 3) { | ||
case 0: | ||
return res; | ||
case 1: | ||
return res + "=="; | ||
case 2: | ||
return res + "="; | ||
default: // When could this happen ? | ||
console.warn("Something in compressToBetterBase64() is very very wrong."); | ||
return ""; | ||
} | ||
|
||
} | ||
|
||
export function decompressFromBetterBase64(input: string): string { | ||
if (!input) { | ||
return ""; | ||
} | ||
const res = _decompress(input.length, 32, (index) => getBaseValue(keyStrBase64, input.charAt(index))); | ||
return res || ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { compressToBase64 } from "./compressToBase64"; | ||
export { decompressFromBase64 } from "./decompressFromBase64"; | ||
export { compressToBetterBase64, decompressFromBetterBase64 } from "./betterBase64"; | ||
export { compressToBase64URL, decompressFromBase64URL } from "./base64URL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
type VERSIONS = "v2.0.0" | ||
|
||
export function deprecated( | ||
thing: string, | ||
version: VERSIONS, | ||
opts?: { replacement?: string } | ||
): void { | ||
let notice = `LZString | ${thing} is deprecated as of: ${version}` | ||
if (opts?.replacement) { | ||
notice += ` - Please use ${opts.replacement} instead` | ||
} | ||
console.error(notice) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function compressKnownString_test(compressFunc, data, compressedData) { | ||
test(`expected compression result`, () => { | ||
expect(compressFunc(data)).toEqual(compressedData); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function decompressKnownString_test(decompressFunc, data, compressedData) { | ||
test(`expected decompression result`, () => { | ||
expect(decompressFunc(compressedData)).toEqual(data); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function emptyShouldBeEmptyResponse_test(compressFunc, decompressFunc, data) { | ||
test(`"" (empty string)`, () => { | ||
const compressedEmpty = compressFunc(data); | ||
|
||
expect(compressedEmpty).toEqual(compressFunc(data)); | ||
expect(compressedEmpty).toEqual(""); | ||
compressedEmpty instanceof Uint8Array | ||
? expect(compressedEmpty.length).not.toBe(0) | ||
: expect(typeof compressedEmpty).toBe("string"); | ||
expect(decompressFunc(compressedEmpty)).toEqual(data); | ||
}); | ||
} | ||
|
||
export function emptyShouldNotBeEmptyResponse_test(compressFunc, decompressFunc, data) { | ||
test(`"" (empty string)`, () => { | ||
const compressedEmpty = compressFunc(data); | ||
|
||
expect(compressedEmpty).toEqual(compressFunc(data)); | ||
expect(compressedEmpty).not.toEqual(""); | ||
compressedEmpty instanceof Uint8Array | ||
? expect(compressedEmpty.length).not.toBe(0) | ||
: expect(typeof compressedEmpty).toBe("string"); | ||
expect(decompressFunc(compressedEmpty)).toEqual(data); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function helloWorld_test(compressFunc, decompressFunc, data) { | ||
test(`"Hello World"`, () => { | ||
const compressedHw = compressFunc(data); | ||
|
||
expect(compressedHw).toEqual(compressFunc(data)); | ||
expect(compressedHw).not.toEqual(data); | ||
expect(decompressFunc(compressedHw)).toEqual(data); | ||
}); | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function interchangableChars_test(decompressFunc, data, compressedData) { | ||
test(`+ and ' ' are interchangeable in decompression`, () => { | ||
expect(data).toEqual(decompressFunc(compressedData)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export * from "./helloWorld"; | ||
export * from "./nullResponse"; | ||
export * from "./emptyResponse"; | ||
export * from "./undefinedResponse"; | ||
export * from "./utf16Response"; | ||
export * from "./repeatingString"; | ||
export * from "./randomString"; | ||
export * from "./longString"; | ||
export * from "./urlSafe"; | ||
export * from "./inchangableChars"; | ||
export * from "./compressTattoo"; | ||
export * from "./decompressTattoo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function longString_test(compressFunc, decompressFunc, data, compressedData) { | ||
test(`Long String`, () => { | ||
expect(compressedData).toEqual(compressFunc(data)); | ||
expect(compressedData).not.toEqual(data); | ||
expect(compressedData.length).toBeLessThan(data.length); | ||
expect(decompressFunc(compressedData)).toEqual(data); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function nullShouldNotBeNullResponse_test(compressFunc, decompressFunc, data) { | ||
test(`null`, () => { | ||
const compressedNull = compressFunc(data); | ||
|
||
compressedNull instanceof Uint8Array | ||
? expect(compressedNull.length).toBe(0) | ||
: expect(compressedNull).toEqual(""); | ||
}); | ||
} | ||
|
||
export function nullShouldBeNullResponse_test(compressFunc, decompressFunc, data) { | ||
test(`null`, () => { | ||
const compressedNull = compressFunc(data); | ||
expect(compressedNull).toEqual(null); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { expect, test } from "vitest"; | ||
import { test_randomString_fn } from "../testValues"; | ||
|
||
export function randomString_test(compressFunc, decompressFunc) { | ||
// Note that this is designed to be uncompressible | ||
test(`Random String`, () => { | ||
const test_randomString = test_randomString_fn(); // Unique per test | ||
const compressedRandomString = compressFunc(test_randomString); | ||
|
||
expect(compressedRandomString).toEqual(compressFunc(test_randomString)); | ||
expect(compressedRandomString).not.toEqual(test_randomString); | ||
expect(decompressFunc(compressedRandomString)).toEqual(test_randomString); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function repeatingString_test(compressFunc, decompressFunc, data) { | ||
test(`Repeating String`, () => { | ||
const compressedRepeat = compressFunc(data); | ||
|
||
expect(compressedRepeat).toEqual(compressFunc(data)); | ||
expect(compressedRepeat).not.toEqual(data); | ||
expect(compressedRepeat.length).toBeLessThan(data.length); | ||
expect(decompressFunc(compressedRepeat)).toEqual(data); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function undefinedResponse_test(compressFunc, decompressFunc, data) { | ||
test(`undefined`, () => { | ||
const compressedUndefined = compressFunc(data); | ||
|
||
compressedUndefined instanceof Uint8Array | ||
? expect(compressedUndefined.length).toBe(0) | ||
: expect(compressedUndefined).toBe(""); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function allCharsUrlSafe_test(compressFunc, decompressFunc, data, compressedData) { | ||
test(`All chars are URL safe`, () => { | ||
expect(compressedData.indexOf("=")).toBe(-1); | ||
expect(compressedData.indexOf("/")).toBe(-1); | ||
expect(decompressFunc(compressedData)).toBe(data); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
export function utf16Response_test(compressFunc, decompressFunc, data) { | ||
test(`utf16`, () => { | ||
const compressedUtf16 = compressFunc(data); | ||
|
||
expect(compressedUtf16).toEqual(compressFunc(data)); | ||
expect(compressedUtf16).not.toEqual(data); | ||
expect(decompressFunc(compressedUtf16)).toEqual(data); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't doing quite what you expect - previously it was running the build if it hadn't run already - we actually don't need that conditional run, so can just have
vitest
on its own - I was mixing upvite preview
andvitest
!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run build
is required to capture changes to the codebase because tests run specifically against the files in /dist, and without it the test system will only reflect changes to the tests themselves.test:build
forces a build of the codebase to ensure all tests run successfully against the latest code.if there is another way to capture code changes in list I would love to use it because this honestly isn't great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - it still needs that ternary for the moment then - I'm about to be pushing a test update that tests the built cjs (currently) via the new commandline tool and a bash script (the intention is that other implementations can support the same arguments and then run the same tests) - currently I can't get nodejs to load binary data properly though, so raw and uint8array both fail to decode :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the test code has been updated and fixed, so it works properly - the test strategy will be changing slightly for the production code so it'll only run when it can (and force it on github itself) - so I'll clean up this when I get to it - can undo the change in the meantime :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can now be removed - the test stategy has been updated (including better tests for built code, and an external test tool here - I'll get it running in github actions soon!)