From 1a3e8058b5d61bc8979fba767fc6f83f8ffa99bf Mon Sep 17 00:00:00 2001 From: softvar Date: Thu, 20 Jun 2024 03:56:05 +0530 Subject: [PATCH] chore: update examples snippets --- .husky/pre-push | 1 - example/aes-compressed-realm.js | 11 +++-- example/aes-compressed.js | 12 +++--- example/aes-uncompressed.js | 6 +-- example/base64-compressed.js | 4 +- example/des-compressed.js | 6 +-- example/des-uncompressed.js | 6 +-- example/index.html | 72 +++++++++++++++++---------------- example/only-base64.js | 6 +-- example/only-compressed.js | 6 +-- example/rabbit-compressed.js | 6 +-- example/rabbit-uncompressed.js | 6 +-- example/rc4-compressed.js | 6 +-- example/rc4-uncompressed.js | 6 +-- example/standard.js | 6 +-- 15 files changed, 84 insertions(+), 76 deletions(-) diff --git a/.husky/pre-push b/.husky/pre-push index 041d054..35944e4 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,4 +1,3 @@ -yarn check:license yarn lint yarn test:prod yarn build diff --git a/example/aes-compressed-realm.js b/example/aes-compressed-realm.js index 999cb43..5a09827 100644 --- a/example/aes-compressed-realm.js +++ b/example/aes-compressed-realm.js @@ -1,10 +1,15 @@ -var data = {data: [{age: 1}, {age: '2'}]}; -var aesCRealm1 = new SecureLS({encodingType: 'aes', encryptionSecret: 'secret1', encryptionNamespace: 'realm1'}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var aesCRealm1 = new SecureLS({ + encodingType: 'aes', + encryptionSecret: 'secret1', + encryptionNamespace: 'realm1', + metaKey: '__meta__', +}); var key1 = 'aes__compressed_1'; var ae = aesCRealm1.AES.encrypt(JSON.stringify(data), ''); var bde = aesCRealm1.AES.decrypt(ae.toString(), ''); var de = bde.toString(aesCRealm1.enc._Utf8); -var aesCRealm2 = new SecureLS({encodingType: 'aes', encryptionSecret: 'secret2', encryptionNamespace: 'realm2'}); +var aesCRealm2 = new SecureLS({ encodingType: 'aes', encryptionSecret: 'secret2', encryptionNamespace: 'realm2' }); var key2 = 'aes__compressed_2'; var ae2 = aesCRealm2.AES.encrypt(JSON.stringify(data), ''); var bde2 = aesCRealm2.AES.decrypt(ae2.toString(), ''); diff --git a/example/aes-compressed.js b/example/aes-compressed.js index 7e09d96..03310c7 100644 --- a/example/aes-compressed.js +++ b/example/aes-compressed.js @@ -1,12 +1,12 @@ var key = 'aes__compressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var aes_c = new SecureLS({encodingType: 'aes', encryptionSecret: ''}); -ae = aes_c.AES.encrypt(JSON.stringify(data), '') -bde = aes_c.AES.decrypt(ae.toString(), '') -de = bde.toString(aes_c.enc._Utf8) +var data = { data: [{ age: 1 }, { age: '2' }] }; +var aes_c = new SecureLS({ encodingType: 'aes', encryptionSecret: '' }); +ae = aes_c.AES.encrypt(JSON.stringify(data), ''); +bde = aes_c.AES.decrypt(ae.toString(), ''); +de = bde.toString(aes_c.enc._Utf8); aes_c.set(key, data); console.log('AES Compressed'); console.log(localStorage.getItem(key)); console.log(aes_c.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/aes-uncompressed.js b/example/aes-uncompressed.js index 4a90a71..7f3f1c9 100644 --- a/example/aes-uncompressed.js +++ b/example/aes-uncompressed.js @@ -1,6 +1,6 @@ var key = 'aes__uncompressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var aes_u = new SecureLS({encodingType: 'aes', isCompression: false}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var aes_u = new SecureLS({ encodingType: 'aes', isCompression: false }); ae = aes_u.AES.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = aes_u.AES.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(aes_u.enc._Utf8); @@ -9,4 +9,4 @@ aes_u.set(key, data); console.log('AES NOT Compressed'); console.log(localStorage.getItem(key)); console.log(aes_u.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/base64-compressed.js b/example/base64-compressed.js index 32b1814..156e9ac 100644 --- a/example/base64-compressed.js +++ b/example/base64-compressed.js @@ -1,5 +1,5 @@ var key = 'base64__compressed'; -var data = {data: [{age: 1}, {age: '2'}]}; +var data = { data: [{ age: 1 }, { age: '2' }] }; var b_c = new SecureLS(); ae = b_c.AES.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = b_c.AES.decrypt(ae.toString(), 's3cr3t@123'); @@ -9,4 +9,4 @@ b_c.set(key, data); console.log('Base64 Compressed'); console.log(localStorage.getItem(key)); console.log(b_c.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/des-compressed.js b/example/des-compressed.js index c9acf4f..c7971fd 100644 --- a/example/des-compressed.js +++ b/example/des-compressed.js @@ -1,6 +1,6 @@ var key = 'des__compressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var des_c = new SecureLS({encodingType: 'des'}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var des_c = new SecureLS({ encodingType: 'des' }); ae = des_c.DES.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = des_c.DES.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(des_c.enc._Utf8); @@ -9,4 +9,4 @@ des_c.set(key, data); console.log('DES Compressed'); console.log(localStorage.getItem(key)); console.log(des_c.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/des-uncompressed.js b/example/des-uncompressed.js index 38e0f1d..130fcef 100644 --- a/example/des-uncompressed.js +++ b/example/des-uncompressed.js @@ -1,6 +1,6 @@ var key = 'des__uncompressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var des_u = new SecureLS({encodingType: 'des', isCompression: false}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var des_u = new SecureLS({ encodingType: 'des', isCompression: false }); ae = des_u.DES.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = des_u.DES.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(des_u.enc._Utf8); @@ -9,4 +9,4 @@ des_u.set(key, data); console.log('DES not Compressed'); console.log(localStorage.getItem(key)); console.log(des_u.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/index.html b/example/index.html index 2007d9d..a49d29f 100644 --- a/example/index.html +++ b/example/index.html @@ -1,36 +1,40 @@ - + - - Example Page - - + + Example Page + + + + + + Open console to check localStorage data. +
+ All of the console output from various examples will be log here. Scroll within it to view all logs. +

+ Input: +
{"data":[{"age":1},{"age":"2"}]}
+ Output: +
{"data":[{"age":1},{"age":"2"}]}
+ - - - Open console to check localStorage data. -
- All of the console output from various examples will be log here. Scroll within it to view all logs. -

- Input:
{"data":[{"age":1},{"age":"2"}]}
- Output:
{"data":[{"age":1},{"age":"2"}]}
- - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + diff --git a/example/only-base64.js b/example/only-base64.js index 97f3968..1f2bafb 100644 --- a/example/only-base64.js +++ b/example/only-base64.js @@ -1,6 +1,6 @@ var key = 'only__base64'; -var data = {data: [{age: 1}, {age: '2'}]}; -var o_b = new SecureLS({isCompression: false}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var o_b = new SecureLS({ isCompression: false }); ae = o_b.AES.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = o_b.AES.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(o_b.enc._Utf8); @@ -9,4 +9,4 @@ o_b.set(key, data); console.log('Only Base64, no compression'); console.log(localStorage.getItem(key)); console.log(o_b.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/only-compressed.js b/example/only-compressed.js index fec843d..f68ebd1 100644 --- a/example/only-compressed.js +++ b/example/only-compressed.js @@ -1,6 +1,6 @@ var key = 'only__compressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var o_c = new SecureLS({encodingType: ''}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var o_c = new SecureLS({ encodingType: '' }); ae = o_c.AES.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = o_c.AES.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(o_c.enc._Utf8); @@ -9,4 +9,4 @@ o_c.set(key, data); console.log('Only Compression, no encoding/encryption'); console.log(localStorage.getItem(key)); console.log(o_c.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/rabbit-compressed.js b/example/rabbit-compressed.js index c929b76..39554d3 100644 --- a/example/rabbit-compressed.js +++ b/example/rabbit-compressed.js @@ -1,6 +1,6 @@ var key = 'rabbit__compressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var rabbit_c = new SecureLS({encodingType: 'rabbit'}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var rabbit_c = new SecureLS({ encodingType: 'rabbit' }); ae = rabbit_c.RABBIT.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = rabbit_c.RABBIT.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(rabbit_c.enc._Utf8); @@ -9,4 +9,4 @@ rabbit_c.set(key, data); console.log('RABBIT Compressed'); console.log(localStorage.getItem(key)); console.log(rabbit_c.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/rabbit-uncompressed.js b/example/rabbit-uncompressed.js index 56d7a23..c8797d4 100644 --- a/example/rabbit-uncompressed.js +++ b/example/rabbit-uncompressed.js @@ -1,6 +1,6 @@ var key = 'rabbit__uncompressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var rabbit_u = new SecureLS({encodingType: 'rabbit', isCompression: false}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var rabbit_u = new SecureLS({ encodingType: 'rabbit', isCompression: false }); ae = rabbit_u.RABBIT.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = rabbit_u.RABBIT.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(rabbit_u.enc._Utf8); @@ -9,4 +9,4 @@ rabbit_u.set(key, data); console.log('RABBIT not Compressed'); console.log(localStorage.getItem(key)); console.log(rabbit_u.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/rc4-compressed.js b/example/rc4-compressed.js index aae241c..7cf2699 100644 --- a/example/rc4-compressed.js +++ b/example/rc4-compressed.js @@ -1,6 +1,6 @@ var key = 'rc4__compressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var rc4_c = new SecureLS({encodingType: 'rc4'}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var rc4_c = new SecureLS({ encodingType: 'rc4' }); ae = rc4_c.RC4.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = rc4_c.RC4.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(rc4_c.enc._Utf8); @@ -9,4 +9,4 @@ rc4_c.set(key, data); console.log('RC4 Compressed'); console.log(localStorage.getItem(key)); console.log(rc4_c.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/rc4-uncompressed.js b/example/rc4-uncompressed.js index f300a6a..bac29af 100644 --- a/example/rc4-uncompressed.js +++ b/example/rc4-uncompressed.js @@ -1,6 +1,6 @@ var key = 'rc4__uncompressed'; -var data = {data: [{age: 1}, {age: '2'}]}; -var rc4_u = new SecureLS({encodingType: 'rc4', isCompression: false}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var rc4_u = new SecureLS({ encodingType: 'rc4', isCompression: false }); ae = rc4_u.RC4.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = rc4_u.RC4.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(rc4_u.enc._Utf8); @@ -9,4 +9,4 @@ rc4_u.set(key, data); console.log('RC4 not Compressed'); console.log(localStorage.getItem(key)); console.log(rc4_u.get(key)); -console.log('____________________________________') \ No newline at end of file +console.log('____________________________________'); diff --git a/example/standard.js b/example/standard.js index 7835973..d17c78d 100644 --- a/example/standard.js +++ b/example/standard.js @@ -1,6 +1,6 @@ var key = 'standard'; -var data = {data: [{age: 1}, {age: '2'}]}; -var a = new SecureLS({encodingType: '', isCompression: false}); +var data = { data: [{ age: 1 }, { age: '2' }] }; +var a = new SecureLS({ encodingType: '', isCompression: false }); ae = a.AES.encrypt(JSON.stringify(data), 's3cr3t@123'); bde = a.AES.decrypt(ae.toString(), 's3cr3t@123'); de = bde.toString(a.enc._Utf8); @@ -10,4 +10,4 @@ console.log('____________________________________'); console.log('Standard Case: no compression, no encryption / encoding'); console.log(localStorage.getItem(key)); console.log(a.get(key)); -console.log('____________________________________'); \ No newline at end of file +console.log('____________________________________');