Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyshlyaev177 committed Jun 27, 2024
1 parent 4ba2c77 commit db387a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
25 changes: 19 additions & 6 deletions packages/encoder/encoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-secrets/no-secrets */
/* eslint-disable max-len */
import { encode, decode } from './encoder';

describe('encoder', () => {
Expand Down Expand Up @@ -43,8 +45,19 @@ describe('encoder', () => {

it('nested', () => {
expect(
encode({ num: 123, obj1: { obj2: { str: 'my_str' } } }),
).toStrictEqual("❴'num':'∓123','obj1':❴'obj2':❴'str':'my_str'❵❵❵");
encode({
num: 123,
num2: 3.14,
b1: true,
b2: false,
str: 'test string',
n: null,
und: undefined,
obj1: { obj2: { str: 'my_str' } },
}),
).toStrictEqual(
"❴'num':'∓123','num2':'∓3.14','b1':'🗵true','b2':'🗵false','str':'test%20string','n':'∙null','und':'∙undefined','obj1':❴'obj2':❴'str':'my_str'❵❵❵",
);
});
});

Expand Down Expand Up @@ -143,16 +156,16 @@ describe('real life example', () => {
const encoded =
"❴'emails':❴'sha1':⦋'f37224933f5e906904ef1f9aeca3486941664555','8a3c1b25c63e3a402e5e3a8e981054ddfec20a18'⦌,'sha256':⦋'9d67f9cab3b2775dbe38e9f6521c23d20037391c0879e4700fea9e9a7672a79e','65c4bbea793b0ac3d5adb86beac555294df2aac05c932374d1d2e382bfd3ea4c'⦌❵,'client':❴'deviceType':'Personal%20computer','browserLanguage':'en-GB','isUserLoggedIn':'🗵true','countryCode':'ge','isInternalRequest':'🗵false'❵,'id':❴'dmp':'AT56sgZZhNi6E_vvdRIAFf-HXftr%26v%3D2'❵,'numb1':'∓100500','numb2':'∓100.12345','compliance':❴'isCCPAOptIn':'🗵true','isLinkedInEmployee':'🗵false','isFunctionalOptIn':'🗵true','isGeoOptIn':'🗵true','isGDPROptIn':'🗵true','isAdvertisingOptIn':'🗵true','isAnalyticsAndResearchOptIn':'🗵true'❵,'primaryEmail':❴'sha1':'f37224933f5e906904ef1f9aeca3486941664555','sha256':'9d67f9cab3b2775dbe38e9f6521c23d20037391c0879e4700fea9e9a7672a79e'❵,'preference':❴'language':'en-us'❵❵";
it('encode', () => {
let a1 = performance.now();
const a1 = performance.now();
const result = encode(bigObj);
let a2 = performance.now();
const a2 = performance.now();
console.log('encode time', a2 - a1 + ' milliseconds');
expect(result).toEqual(encoded);
});
it('decode', () => {
let a1 = performance.now();
const a1 = performance.now();
const result = decode(encoded);
let a2 = performance.now();
const a2 = performance.now();
expect(result).toStrictEqual(bigObj);
console.log('decode time ', a2 - a1 + ' milliseconds');
});
Expand Down
1 change: 1 addition & 0 deletions packages/encoder/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const parseJSON = (str: string) => {

try {
result = JSON.parse(str, reviver);
// eslint-disable-next-line no-empty
} catch {}

return result;
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const plugins = [
commonjs(),

!isProduction && sourcemaps(),
isProduction && terser(),
isProduction && terser({ ecma: '2020' }),
filesize(),
].filter(Boolean);

Expand Down

0 comments on commit db387a5

Please sign in to comment.