@vercel/stega 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,12 +35,34 @@ This method splits out the original string (cleaned) and the encoded portion of
35
35
  vercelStegaSplit('Hello world');
36
36
  /*
37
37
  * -> {
38
- * cleaned: 'Hello world', // This doesn't contains the encoded data
38
+ * cleaned: 'Hello world', // This doesn't contain the encoded data
39
39
  * encoded: '', // This is not an empty string, it contains the encoded data
40
40
  * }
41
41
  */
42
42
  ```
43
43
 
44
+ ### `vercelStegaClean(json)`
45
+
46
+ This method strips all encoded stega data from the value and returns the cleaned value. It accepts any JSON value.
47
+
48
+ ```js
49
+ // In 'Hello world' (the extra data is hidden)
50
+ vercelStegaClean('Hello world');
51
+ /*
52
+ * -> 'Hello world' // This doesn't contain the encoded data
53
+ */
54
+
55
+ // In 'Hello world' (the extra data is hidden)
56
+ vercelStegaClean({
57
+ nested: {
58
+ value: 'Hello world',
59
+ },
60
+ });
61
+ /*
62
+ * -> { nested: { value: 'Hello world' } } // This doesn't contain the encoded data
63
+ */
64
+ ```
65
+
44
66
  ### `vercelStegaDecode(string)`
45
67
 
46
68
  This method attempts to extract encoded JSON data from a `string`.
package/dist/index.d.ts CHANGED
@@ -49,5 +49,9 @@ interface SplitResult {
49
49
  * @returns The cleaned string and encoded data, separately
50
50
  */
51
51
  declare function vercelStegaSplit(original: string): SplitResult;
52
+ /**
53
+ * Removes all stega-encoded data from a JSON value
54
+ */
55
+ declare function vercelStegaClean<T>(result: T): T;
52
56
 
53
- export { VERCEL_STEGA_REGEX, legacyStegaEncode, vercelStegaCombine, vercelStegaDecode, vercelStegaDecodeAll, vercelStegaEncode, vercelStegaSplit };
57
+ export { VERCEL_STEGA_REGEX, legacyStegaEncode, vercelStegaClean, vercelStegaCombine, vercelStegaDecode, vercelStegaDecodeAll, vercelStegaEncode, vercelStegaSplit };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var s={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},c={0:8203,1:8204,2:8205,3:65279},d=new Array(4).fill(String.fromCodePoint(c[0])).join(""),m=String.fromCharCode(0);function E(t){let e=JSON.stringify(t);return`${d}${Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(4).padStart(4,"0")).map(o=>String.fromCodePoint(c[o])).join("")}).join("")}`}function P(t){let e=JSON.stringify(t);return Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(16).padStart(2,"0")).map(o=>String.fromCodePoint(s[o])).join("")}).join("")}function I(t){return Number.isNaN(Number(t))?Boolean(Date.parse(t)):!1}function x(t){try{new URL(t,t.startsWith("/")?"https://acme.com":void 0)}catch (e2){return!1}return!0}function b(t,e,r="auto"){return r===!0||r==="auto"&&(I(t)||x(t))?t:`${t}${E(e)}`}var A=Object.fromEntries(Object.entries(c).map(t=>t.reverse())),g=Object.fromEntries(Object.entries(s).map(t=>t.reverse())),S=`${Object.values(s).map(t=>`\\u{${t.toString(16)}}`).join("")}`,f= exports.VERCEL_STEGA_REGEX =new RegExp(`[${S}]{4,}`,"gu");function R(t){let e=t.match(f);if(!!e)return h(e[0],!0)[0]}function G(t){let e=t.match(f);if(!!e)return e.map(r=>h(r)).flat()}function h(t,e=!1){let r=Array.from(t);if(r.length%2===0){if(r.length%4||!t.startsWith(d))return T(r,e)}else throw new Error("Encoded data has invalid length");let n=[];for(let o=r.length*.25;o--;){let p=r.slice(o*4,o*4+4).map(u=>A[u.codePointAt(0)]).join("");n.unshift(String.fromCharCode(parseInt(p,4)))}if(e){n.shift();let o=n.indexOf(m);return o===-1&&(o=n.length),[JSON.parse(n.slice(0,o).join(""))]}return n.join("").split(m).filter(Boolean).map(o=>JSON.parse(o))}function T(t,e){var u;let r=[];for(let i=t.length*.5;i--;){let a=`${g[t[i*2].codePointAt(0)]}${g[t[i*2+1].codePointAt(0)]}`;r.unshift(String.fromCharCode(parseInt(a,16)))}let n=[],o=[r.join("")],p=10;for(;o.length;){let i=o.shift();try{if(n.push(JSON.parse(i)),e)return n}catch(a){if(!p--)throw a;let l=+((u=a.message.match(/\sposition\s(\d+)$/))==null?void 0:u[1]);if(!l)throw a;o.unshift(i.substring(0,l),i.substring(l))}}return n}function X(t){var e;return{cleaned:t.replace(f,""),encoded:((e=t.match(f))==null?void 0:e[0])||""}}exports.VERCEL_STEGA_REGEX = f; exports.legacyStegaEncode = P; exports.vercelStegaCombine = b; exports.vercelStegaDecode = R; exports.vercelStegaDecodeAll = G; exports.vercelStegaEncode = E; exports.vercelStegaSplit = X;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var s={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},c={0:8203,1:8204,2:8205,3:65279},d=new Array(4).fill(String.fromCodePoint(c[0])).join(""),m=String.fromCharCode(0);function E(t){let e=JSON.stringify(t);return`${d}${Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(4).padStart(4,"0")).map(o=>String.fromCodePoint(c[o])).join("")}).join("")}`}function y(t){let e=JSON.stringify(t);return Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(16).padStart(2,"0")).map(o=>String.fromCodePoint(s[o])).join("")}).join("")}function I(t){return Number.isNaN(Number(t))?Boolean(Date.parse(t)):!1}function x(t){try{new URL(t,t.startsWith("/")?"https://acme.com":void 0)}catch (e2){return!1}return!0}function C(t,e,r="auto"){return r===!0||r==="auto"&&(I(t)||x(t))?t:`${t}${E(e)}`}var S=Object.fromEntries(Object.entries(c).map(t=>t.reverse())),g=Object.fromEntries(Object.entries(s).map(t=>t.reverse())),T=`${Object.values(s).map(t=>`\\u{${t.toString(16)}}`).join("")}`,f= exports.VERCEL_STEGA_REGEX =new RegExp(`[${T}]{4,}`,"gu");function G(t){let e=t.match(f);if(!!e)return h(e[0],!0)[0]}function $(t){let e=t.match(f);if(!!e)return e.map(r=>h(r)).flat()}function h(t,e=!1){let r=Array.from(t);if(r.length%2===0){if(r.length%4||!t.startsWith(d))return A(r,e)}else throw new Error("Encoded data has invalid length");let n=[];for(let o=r.length*.25;o--;){let l=r.slice(o*4,o*4+4).map(u=>S[u.codePointAt(0)]).join("");n.unshift(String.fromCharCode(parseInt(l,4)))}if(e){n.shift();let o=n.indexOf(m);return o===-1&&(o=n.length),[JSON.parse(n.slice(0,o).join(""))]}return n.join("").split(m).filter(Boolean).map(o=>JSON.parse(o))}function A(t,e){var u;let r=[];for(let i=t.length*.5;i--;){let a=`${g[t[i*2].codePointAt(0)]}${g[t[i*2+1].codePointAt(0)]}`;r.unshift(String.fromCharCode(parseInt(a,16)))}let n=[],o=[r.join("")],l=10;for(;o.length;){let i=o.shift();try{if(n.push(JSON.parse(i)),e)return n}catch(a){if(!l--)throw a;let p=+((u=a.message.match(/\sposition\s(\d+)$/))==null?void 0:u[1]);if(!p)throw a;o.unshift(i.substring(0,p),i.substring(p))}}return n}function _(t){var e;return{cleaned:t.replace(f,""),encoded:((e=t.match(f))==null?void 0:e[0])||""}}function O(t){return JSON.parse(_(JSON.stringify(t)).cleaned)}exports.VERCEL_STEGA_REGEX = f; exports.legacyStegaEncode = y; exports.vercelStegaClean = O; exports.vercelStegaCombine = C; exports.vercelStegaDecode = G; exports.vercelStegaDecodeAll = $; exports.vercelStegaEncode = E; exports.vercelStegaSplit = _;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var s={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},c={0:8203,1:8204,2:8205,3:65279},d=new Array(4).fill(String.fromCodePoint(c[0])).join(""),m=String.fromCharCode(0);function E(t){let e=JSON.stringify(t);return`${d}${Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(4).padStart(4,"0")).map(o=>String.fromCodePoint(c[o])).join("")}).join("")}`}function P(t){let e=JSON.stringify(t);return Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(16).padStart(2,"0")).map(o=>String.fromCodePoint(s[o])).join("")}).join("")}function I(t){return Number.isNaN(Number(t))?Boolean(Date.parse(t)):!1}function x(t){try{new URL(t,t.startsWith("/")?"https://acme.com":void 0)}catch{return!1}return!0}function b(t,e,r="auto"){return r===!0||r==="auto"&&(I(t)||x(t))?t:`${t}${E(e)}`}var A=Object.fromEntries(Object.entries(c).map(t=>t.reverse())),g=Object.fromEntries(Object.entries(s).map(t=>t.reverse())),S=`${Object.values(s).map(t=>`\\u{${t.toString(16)}}`).join("")}`,f=new RegExp(`[${S}]{4,}`,"gu");function R(t){let e=t.match(f);if(!!e)return h(e[0],!0)[0]}function G(t){let e=t.match(f);if(!!e)return e.map(r=>h(r)).flat()}function h(t,e=!1){let r=Array.from(t);if(r.length%2===0){if(r.length%4||!t.startsWith(d))return T(r,e)}else throw new Error("Encoded data has invalid length");let n=[];for(let o=r.length*.25;o--;){let p=r.slice(o*4,o*4+4).map(u=>A[u.codePointAt(0)]).join("");n.unshift(String.fromCharCode(parseInt(p,4)))}if(e){n.shift();let o=n.indexOf(m);return o===-1&&(o=n.length),[JSON.parse(n.slice(0,o).join(""))]}return n.join("").split(m).filter(Boolean).map(o=>JSON.parse(o))}function T(t,e){var u;let r=[];for(let i=t.length*.5;i--;){let a=`${g[t[i*2].codePointAt(0)]}${g[t[i*2+1].codePointAt(0)]}`;r.unshift(String.fromCharCode(parseInt(a,16)))}let n=[],o=[r.join("")],p=10;for(;o.length;){let i=o.shift();try{if(n.push(JSON.parse(i)),e)return n}catch(a){if(!p--)throw a;let l=+((u=a.message.match(/\sposition\s(\d+)$/))==null?void 0:u[1]);if(!l)throw a;o.unshift(i.substring(0,l),i.substring(l))}}return n}function X(t){var e;return{cleaned:t.replace(f,""),encoded:((e=t.match(f))==null?void 0:e[0])||""}}export{f as VERCEL_STEGA_REGEX,P as legacyStegaEncode,b as vercelStegaCombine,R as vercelStegaDecode,G as vercelStegaDecodeAll,E as vercelStegaEncode,X as vercelStegaSplit};
1
+ var s={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},c={0:8203,1:8204,2:8205,3:65279},d=new Array(4).fill(String.fromCodePoint(c[0])).join(""),m=String.fromCharCode(0);function E(t){let e=JSON.stringify(t);return`${d}${Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(4).padStart(4,"0")).map(o=>String.fromCodePoint(c[o])).join("")}).join("")}`}function y(t){let e=JSON.stringify(t);return Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(16).padStart(2,"0")).map(o=>String.fromCodePoint(s[o])).join("")}).join("")}function I(t){return Number.isNaN(Number(t))?Boolean(Date.parse(t)):!1}function x(t){try{new URL(t,t.startsWith("/")?"https://acme.com":void 0)}catch{return!1}return!0}function C(t,e,r="auto"){return r===!0||r==="auto"&&(I(t)||x(t))?t:`${t}${E(e)}`}var S=Object.fromEntries(Object.entries(c).map(t=>t.reverse())),g=Object.fromEntries(Object.entries(s).map(t=>t.reverse())),T=`${Object.values(s).map(t=>`\\u{${t.toString(16)}}`).join("")}`,f=new RegExp(`[${T}]{4,}`,"gu");function G(t){let e=t.match(f);if(!!e)return h(e[0],!0)[0]}function $(t){let e=t.match(f);if(!!e)return e.map(r=>h(r)).flat()}function h(t,e=!1){let r=Array.from(t);if(r.length%2===0){if(r.length%4||!t.startsWith(d))return A(r,e)}else throw new Error("Encoded data has invalid length");let n=[];for(let o=r.length*.25;o--;){let l=r.slice(o*4,o*4+4).map(u=>S[u.codePointAt(0)]).join("");n.unshift(String.fromCharCode(parseInt(l,4)))}if(e){n.shift();let o=n.indexOf(m);return o===-1&&(o=n.length),[JSON.parse(n.slice(0,o).join(""))]}return n.join("").split(m).filter(Boolean).map(o=>JSON.parse(o))}function A(t,e){var u;let r=[];for(let i=t.length*.5;i--;){let a=`${g[t[i*2].codePointAt(0)]}${g[t[i*2+1].codePointAt(0)]}`;r.unshift(String.fromCharCode(parseInt(a,16)))}let n=[],o=[r.join("")],l=10;for(;o.length;){let i=o.shift();try{if(n.push(JSON.parse(i)),e)return n}catch(a){if(!l--)throw a;let p=+((u=a.message.match(/\sposition\s(\d+)$/))==null?void 0:u[1]);if(!p)throw a;o.unshift(i.substring(0,p),i.substring(p))}}return n}function _(t){var e;return{cleaned:t.replace(f,""),encoded:((e=t.match(f))==null?void 0:e[0])||""}}function O(t){return JSON.parse(_(JSON.stringify(t)).cleaned)}export{f as VERCEL_STEGA_REGEX,y as legacyStegaEncode,O as vercelStegaClean,C as vercelStegaCombine,G as vercelStegaDecode,$ as vercelStegaDecodeAll,E as vercelStegaEncode,_ as vercelStegaSplit};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/stega",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Utilities for steganography",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -15,7 +15,8 @@
15
15
  "jest": "^29.6.1",
16
16
  "ts-jest": "^29.1.1",
17
17
  "tsup": "^6.7.0",
18
- "typescript": "^4.6.3"
18
+ "typescript": "^4.6.3",
19
+ "@vercel-private/conformance": "1.7.0"
19
20
  },
20
21
  "access": "public",
21
22
  "publishConfig": {
@@ -24,6 +25,7 @@
24
25
  "scripts": {
25
26
  "dev": "tsup --watch",
26
27
  "build": "tsup",
28
+ "conformance": "vercel-conformance",
27
29
  "test": "jest"
28
30
  }
29
31
  }