diff --git a/packages/encoder/encoder.test.ts b/packages/encoder/encoder.test.ts index a672e9c..b2f40fd 100644 --- a/packages/encoder/encoder.test.ts +++ b/packages/encoder/encoder.test.ts @@ -1,3 +1,5 @@ +/* eslint-disable no-secrets/no-secrets */ +/* eslint-disable max-len */ import { encode, decode } from './encoder'; describe('encoder', () => { @@ -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'❵❵❵", + ); }); }); @@ -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'); }); diff --git a/packages/encoder/encoder.ts b/packages/encoder/encoder.ts index cdfb122..2a069a8 100644 --- a/packages/encoder/encoder.ts +++ b/packages/encoder/encoder.ts @@ -57,6 +57,7 @@ const parseJSON = (str: string) => { try { result = JSON.parse(str, reviver); + // eslint-disable-next-line no-empty } catch {} return result; diff --git a/rollup.config.js b/rollup.config.js index ef2bf31..997e17a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -31,7 +31,7 @@ const plugins = [ commonjs(), !isProduction && sourcemaps(), - isProduction && terser(), + isProduction && terser({ ecma: '2020' }), filesize(), ].filter(Boolean);