@vercel/stega 0.0.5 → 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
@@ -1,3 +1,57 @@
1
- export * from './encode';
2
- export * from './decode';
3
- export * from './util';
1
+ /**
2
+ * Encodes JSON as a hidden string
3
+ * @param json - The JSON data to encode
4
+ * @returns The hidden string
5
+ */
6
+ declare function vercelStegaEncode<T>(json: T): string;
7
+ /**
8
+ * Encodes JSON as a hidden string using the original logic
9
+ * @param json - The JSON data to encode
10
+ * @returns The hidden string
11
+ * @deprecated
12
+ */
13
+ declare function legacyStegaEncode<T>(json: T): string;
14
+ type SkipValue = 'auto' | boolean;
15
+ /**
16
+ * Adds an encoded JSON object to a string as hidden characters
17
+ * @param string - The string the JSON will be added to
18
+ * @param json - The JSON to add to the string
19
+ * @param skip - Whether to skip encoding (default: "auto")
20
+ */
21
+ declare function vercelStegaCombine<T>(string: string, json: T, skip?: SkipValue): string;
22
+
23
+ declare const VERCEL_STEGA_REGEX: RegExp;
24
+ /**
25
+ * Decodes the first hidden string that's found in the source string back into its original value
26
+ * @param source - The source string with encoded data
27
+ * @returns The decoded JSON value
28
+ */
29
+ declare function vercelStegaDecode<T>(source: string): T | undefined;
30
+ /**
31
+ * Decodes every hidden string that's found in the source string back into their original values
32
+ * @param source - The source string with encoded data
33
+ * @returns The decoded JSON values
34
+ */
35
+ declare function vercelStegaDecodeAll<T>(source: string): T[];
36
+
37
+ /**
38
+ * Separated clean string and encoded string
39
+ */
40
+ interface SplitResult {
41
+ /** The original string with encoded substring removed */
42
+ cleaned: string;
43
+ /** The encoded substring from the original string */
44
+ encoded: string;
45
+ }
46
+ /**
47
+ * Splits out encoded data from a string, if any is found
48
+ * @param original - The original string
49
+ * @returns The cleaned string and encoded data, separately
50
+ */
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;
56
+
57
+ export { VERCEL_STEGA_REGEX, legacyStegaEncode, vercelStegaClean, vercelStegaCombine, vercelStegaDecode, vercelStegaDecodeAll, vercelStegaEncode, vercelStegaSplit };
package/dist/index.js ADDED
@@ -0,0 +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 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 ADDED
@@ -0,0 +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 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,9 +1,9 @@
1
1
  {
2
2
  "name": "@vercel/stega",
3
- "version": "0.0.5",
3
+ "version": "0.1.1",
4
4
  "description": "Utilities for steganography",
5
- "main": "./dist/cjs/index.js",
6
- "module": "./dist/esm/index.js",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
8
  "source": "./src/index.ts",
9
9
  "files": [
@@ -11,21 +11,21 @@
11
11
  ],
12
12
  "license": "MPL-2.0",
13
13
  "devDependencies": {
14
- "@jest/globals": "^28.1.3",
15
- "jest": "^28.1.3",
16
- "ts-jest": "^28.0.3",
17
- "typescript": "^4.6.3"
14
+ "@jest/globals": "^29.6.1",
15
+ "jest": "^29.6.1",
16
+ "ts-jest": "^29.1.1",
17
+ "tsup": "^6.7.0",
18
+ "typescript": "^4.6.3",
19
+ "@vercel-private/conformance": "1.7.0"
18
20
  },
19
21
  "access": "public",
20
22
  "publishConfig": {
21
23
  "access": "public"
22
24
  },
23
25
  "scripts": {
24
- "dev": "pnpm build",
25
- "build": "pnpm build:types && pnpm build:esm && pnpm build:cjs",
26
- "build:esm": "tsc --module es2020 --outDir dist/esm",
27
- "build:cjs": "tsc --module commonjs --outDir dist/cjs",
28
- "build:types": "tsc --declaration --emitDeclarationOnly",
26
+ "dev": "tsup --watch",
27
+ "build": "tsup",
28
+ "conformance": "vercel-conformance",
29
29
  "test": "jest"
30
30
  }
31
31
  }
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vercelStegaDecodeAll = exports.vercelStegaDecode = exports.VERCEL_STEGA_REGEX = void 0;
4
- const map_1 = require("./map");
5
- const REVERSE_HEX_DIGIT_MAP = Object.fromEntries(Object.entries(map_1.HEX_DIGIT_MAP).map((x) => x.reverse()));
6
- const HEX_CHARS = `${Object.values(map_1.HEX_DIGIT_MAP)
7
- .map((x) => `\\u{${x.toString(16)}}`)
8
- .join('')}`;
9
- exports.VERCEL_STEGA_REGEX = new RegExp(`(?:[${HEX_CHARS}]{2})+`, 'gu');
10
- /**
11
- * Decodes the first hidden string that's found in the source string back into its original value
12
- * @param source - The source string with encoded data
13
- * @returns The decoded JSON value
14
- */
15
- function vercelStegaDecode(source) {
16
- const matches = source.match(exports.VERCEL_STEGA_REGEX);
17
- if (!matches)
18
- return;
19
- return decode(matches[0], true)[0];
20
- }
21
- exports.vercelStegaDecode = vercelStegaDecode;
22
- /**
23
- * Decodes every hidden string that's found in the source string back into their original values
24
- * @param source - The source string with encoded data
25
- * @returns The decoded JSON values
26
- */
27
- function vercelStegaDecodeAll(source) {
28
- const matches = source.match(exports.VERCEL_STEGA_REGEX);
29
- if (!matches)
30
- return;
31
- return matches.map((match) => decode(match)).flat();
32
- }
33
- exports.vercelStegaDecodeAll = vercelStegaDecodeAll;
34
- function decode(encodedString, firstOnly = false) {
35
- var _a;
36
- const encoded = Array.from(encodedString);
37
- if (encoded.length % 2) {
38
- throw new Error(`Invalid encoded text length. Expected length to be even, received: ${encoded.length}`);
39
- }
40
- const chars = [];
41
- for (let i = encoded.length * 0.5; i--;) {
42
- const hex = `${REVERSE_HEX_DIGIT_MAP[encoded[i * 2].codePointAt(0)]}${REVERSE_HEX_DIGIT_MAP[encoded[i * 2 + 1].codePointAt(0)]}`;
43
- chars.unshift(String.fromCharCode(parseInt(hex, 16)));
44
- }
45
- const results = [];
46
- const queue = [chars.join('')];
47
- let breakLimit = 10;
48
- while (queue.length) {
49
- const string = queue.shift();
50
- try {
51
- results.push(JSON.parse(string));
52
- if (firstOnly)
53
- return results;
54
- }
55
- catch (error) {
56
- if (!breakLimit--)
57
- throw error;
58
- const position = +((_a = error.message.match(/\sposition\s(\d+)$/)) === null || _a === void 0 ? void 0 : _a[1]);
59
- if (!position)
60
- throw error;
61
- queue.unshift(string.substring(0, position), string.substring(position));
62
- }
63
- }
64
- return results;
65
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vercelStegaCombine = exports.vercelStegaEncode = void 0;
4
- const map_1 = require("./map");
5
- /**
6
- * Encodes JSON as a hidden string
7
- * @param json - The JSON data to encode
8
- * @returns The hidden string
9
- */
10
- function vercelStegaEncode(json) {
11
- const string = JSON.stringify(json);
12
- return Array.from(string)
13
- .map((character) => {
14
- const charCode = character.charCodeAt(0);
15
- if (charCode > 255) {
16
- throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${string} on character ${character} (${charCode})`);
17
- }
18
- return Array.from(charCode.toString(16).padStart(2, '0'))
19
- .map((hex) => String.fromCodePoint(map_1.HEX_DIGIT_MAP[hex]))
20
- .join('');
21
- })
22
- .join('');
23
- }
24
- exports.vercelStegaEncode = vercelStegaEncode;
25
- function isDate(string) {
26
- return Boolean(Date.parse(string));
27
- }
28
- function isUrl(string) {
29
- try {
30
- new URL(string);
31
- }
32
- catch {
33
- return false;
34
- }
35
- return true;
36
- }
37
- /**
38
- * Adds an encoded JSON object to a string as hidden characters
39
- * @param string - The string the JSON will be added to
40
- * @param json - The JSON to add to the string
41
- * @param skip - Whether to skip encoding (default: "auto")
42
- */
43
- function vercelStegaCombine(string, json, skip = 'auto') {
44
- if (skip === true)
45
- return string;
46
- if (skip === 'auto' && (isDate(string) || isUrl(string)))
47
- return string;
48
- return `${string}${vercelStegaEncode(json)}`;
49
- }
50
- exports.vercelStegaCombine = vercelStegaCombine;
package/dist/cjs/index.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./encode"), exports);
18
- __exportStar(require("./decode"), exports);
19
- __exportStar(require("./util"), exports);
package/dist/cjs/map.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HEX_DIGIT_MAP = void 0;
4
- exports.HEX_DIGIT_MAP = {
5
- 0: 0x200b,
6
- 1: 0x200c,
7
- 2: 0x200d,
8
- 3: 0x2062,
9
- 4: 0x2063,
10
- 5: 0x2060,
11
- 6: 0xfeff,
12
- 7: 0x2061,
13
- 8: 0x1d173,
14
- 9: 0x1d174,
15
- a: 0x1d175,
16
- b: 0x1d176,
17
- c: 0x1d177,
18
- d: 0x1d178,
19
- e: 0x1d179,
20
- f: 0x1d17a,
21
- };
package/dist/cjs/util.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vercelStegaSplit = void 0;
4
- const decode_1 = require("./decode");
5
- /**
6
- * Splits out encoded data from a string, if any is found
7
- * @param original - The original string
8
- * @returns The cleaned string and encoded data, separately
9
- */
10
- function vercelStegaSplit(original) {
11
- var _a;
12
- return {
13
- cleaned: original.replace(decode_1.VERCEL_STEGA_REGEX, ''),
14
- encoded: ((_a = original.match(decode_1.VERCEL_STEGA_REGEX)) === null || _a === void 0 ? void 0 : _a[0]) || '',
15
- };
16
- }
17
- exports.vercelStegaSplit = vercelStegaSplit;
package/dist/decode.d.ts DELETED
@@ -1,13 +0,0 @@
1
- export declare const VERCEL_STEGA_REGEX: RegExp;
2
- /**
3
- * Decodes the first hidden string that's found in the source string back into its original value
4
- * @param source - The source string with encoded data
5
- * @returns The decoded JSON value
6
- */
7
- export declare function vercelStegaDecode<T>(source: string): T | undefined;
8
- /**
9
- * Decodes every hidden string that's found in the source string back into their original values
10
- * @param source - The source string with encoded data
11
- * @returns The decoded JSON values
12
- */
13
- export declare function vercelStegaDecodeAll<T>(source: string): T[];
package/dist/encode.d.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * Encodes JSON as a hidden string
3
- * @param json - The JSON data to encode
4
- * @returns The hidden string
5
- */
6
- export declare function vercelStegaEncode<T>(json: T): string;
7
- type SkipValue = 'auto' | boolean;
8
- /**
9
- * Adds an encoded JSON object to a string as hidden characters
10
- * @param string - The string the JSON will be added to
11
- * @param json - The JSON to add to the string
12
- * @param skip - Whether to skip encoding (default: "auto")
13
- */
14
- export declare function vercelStegaCombine<T>(string: string, json: T, skip?: SkipValue): string;
15
- export {};
@@ -1,60 +0,0 @@
1
- import { HEX_DIGIT_MAP } from './map';
2
- const REVERSE_HEX_DIGIT_MAP = Object.fromEntries(Object.entries(HEX_DIGIT_MAP).map((x) => x.reverse()));
3
- const HEX_CHARS = `${Object.values(HEX_DIGIT_MAP)
4
- .map((x) => `\\u{${x.toString(16)}}`)
5
- .join('')}`;
6
- export const VERCEL_STEGA_REGEX = new RegExp(`(?:[${HEX_CHARS}]{2})+`, 'gu');
7
- /**
8
- * Decodes the first hidden string that's found in the source string back into its original value
9
- * @param source - The source string with encoded data
10
- * @returns The decoded JSON value
11
- */
12
- export function vercelStegaDecode(source) {
13
- const matches = source.match(VERCEL_STEGA_REGEX);
14
- if (!matches)
15
- return;
16
- return decode(matches[0], true)[0];
17
- }
18
- /**
19
- * Decodes every hidden string that's found in the source string back into their original values
20
- * @param source - The source string with encoded data
21
- * @returns The decoded JSON values
22
- */
23
- export function vercelStegaDecodeAll(source) {
24
- const matches = source.match(VERCEL_STEGA_REGEX);
25
- if (!matches)
26
- return;
27
- return matches.map((match) => decode(match)).flat();
28
- }
29
- function decode(encodedString, firstOnly = false) {
30
- var _a;
31
- const encoded = Array.from(encodedString);
32
- if (encoded.length % 2) {
33
- throw new Error(`Invalid encoded text length. Expected length to be even, received: ${encoded.length}`);
34
- }
35
- const chars = [];
36
- for (let i = encoded.length * 0.5; i--;) {
37
- const hex = `${REVERSE_HEX_DIGIT_MAP[encoded[i * 2].codePointAt(0)]}${REVERSE_HEX_DIGIT_MAP[encoded[i * 2 + 1].codePointAt(0)]}`;
38
- chars.unshift(String.fromCharCode(parseInt(hex, 16)));
39
- }
40
- const results = [];
41
- const queue = [chars.join('')];
42
- let breakLimit = 10;
43
- while (queue.length) {
44
- const string = queue.shift();
45
- try {
46
- results.push(JSON.parse(string));
47
- if (firstOnly)
48
- return results;
49
- }
50
- catch (error) {
51
- if (!breakLimit--)
52
- throw error;
53
- const position = +((_a = error.message.match(/\sposition\s(\d+)$/)) === null || _a === void 0 ? void 0 : _a[1]);
54
- if (!position)
55
- throw error;
56
- queue.unshift(string.substring(0, position), string.substring(position));
57
- }
58
- }
59
- return results;
60
- }
@@ -1,45 +0,0 @@
1
- import { HEX_DIGIT_MAP } from './map';
2
- /**
3
- * Encodes JSON as a hidden string
4
- * @param json - The JSON data to encode
5
- * @returns The hidden string
6
- */
7
- export function vercelStegaEncode(json) {
8
- const string = JSON.stringify(json);
9
- return Array.from(string)
10
- .map((character) => {
11
- const charCode = character.charCodeAt(0);
12
- if (charCode > 255) {
13
- throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${string} on character ${character} (${charCode})`);
14
- }
15
- return Array.from(charCode.toString(16).padStart(2, '0'))
16
- .map((hex) => String.fromCodePoint(HEX_DIGIT_MAP[hex]))
17
- .join('');
18
- })
19
- .join('');
20
- }
21
- function isDate(string) {
22
- return Boolean(Date.parse(string));
23
- }
24
- function isUrl(string) {
25
- try {
26
- new URL(string);
27
- }
28
- catch {
29
- return false;
30
- }
31
- return true;
32
- }
33
- /**
34
- * Adds an encoded JSON object to a string as hidden characters
35
- * @param string - The string the JSON will be added to
36
- * @param json - The JSON to add to the string
37
- * @param skip - Whether to skip encoding (default: "auto")
38
- */
39
- export function vercelStegaCombine(string, json, skip = 'auto') {
40
- if (skip === true)
41
- return string;
42
- if (skip === 'auto' && (isDate(string) || isUrl(string)))
43
- return string;
44
- return `${string}${vercelStegaEncode(json)}`;
45
- }
package/dist/esm/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from './encode';
2
- export * from './decode';
3
- export * from './util';
package/dist/esm/map.js DELETED
@@ -1,18 +0,0 @@
1
- export const HEX_DIGIT_MAP = {
2
- 0: 0x200b,
3
- 1: 0x200c,
4
- 2: 0x200d,
5
- 3: 0x2062,
6
- 4: 0x2063,
7
- 5: 0x2060,
8
- 6: 0xfeff,
9
- 7: 0x2061,
10
- 8: 0x1d173,
11
- 9: 0x1d174,
12
- a: 0x1d175,
13
- b: 0x1d176,
14
- c: 0x1d177,
15
- d: 0x1d178,
16
- e: 0x1d179,
17
- f: 0x1d17a,
18
- };
package/dist/esm/util.js DELETED
@@ -1,13 +0,0 @@
1
- import { VERCEL_STEGA_REGEX } from './decode';
2
- /**
3
- * Splits out encoded data from a string, if any is found
4
- * @param original - The original string
5
- * @returns The cleaned string and encoded data, separately
6
- */
7
- export function vercelStegaSplit(original) {
8
- var _a;
9
- return {
10
- cleaned: original.replace(VERCEL_STEGA_REGEX, ''),
11
- encoded: ((_a = original.match(VERCEL_STEGA_REGEX)) === null || _a === void 0 ? void 0 : _a[0]) || '',
12
- };
13
- }
package/dist/map.d.ts DELETED
@@ -1,18 +0,0 @@
1
- export declare const HEX_DIGIT_MAP: {
2
- 0: number;
3
- 1: number;
4
- 2: number;
5
- 3: number;
6
- 4: number;
7
- 5: number;
8
- 6: number;
9
- 7: number;
10
- 8: number;
11
- 9: number;
12
- a: number;
13
- b: number;
14
- c: number;
15
- d: number;
16
- e: number;
17
- f: number;
18
- };
package/dist/util.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * Separated clean string and encoded string
3
- */
4
- interface SplitResult {
5
- /** The original string with encoded substring removed */
6
- cleaned: string;
7
- /** The encoded substring from the original string */
8
- encoded: string;
9
- }
10
- /**
11
- * Splits out encoded data from a string, if any is found
12
- * @param original - The original string
13
- * @returns The cleaned string and encoded data, separately
14
- */
15
- export declare function vercelStegaSplit(original: string): SplitResult;
16
- export {};