@vercel/stega 0.0.3 → 0.0.4
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/dist/cjs/decode.js +41 -9
- package/dist/decode.d.ts +9 -3
- package/dist/esm/decode.js +39 -8
- package/package.json +1 -1
package/dist/cjs/decode.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.vercelStegaDecode = exports.VERCEL_STEGA_REGEX = void 0;
|
|
3
|
+
exports.vercelStegaDecodeAll = exports.vercelStegaDecode = exports.VERCEL_STEGA_REGEX = void 0;
|
|
4
4
|
const map_1 = require("./map");
|
|
5
5
|
const REVERSE_HEX_DIGIT_MAP = Object.fromEntries(Object.entries(map_1.HEX_DIGIT_MAP).map((x) => x.reverse()));
|
|
6
6
|
const HEX_CHARS = `${Object.values(map_1.HEX_DIGIT_MAP)
|
|
@@ -8,18 +8,31 @@ const HEX_CHARS = `${Object.values(map_1.HEX_DIGIT_MAP)
|
|
|
8
8
|
.join('')}`;
|
|
9
9
|
exports.VERCEL_STEGA_REGEX = new RegExp(`(?:[${HEX_CHARS}]{2})+`, 'gu');
|
|
10
10
|
/**
|
|
11
|
-
* Decodes
|
|
12
|
-
* @param
|
|
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
13
|
* @returns The decoded JSON value
|
|
14
14
|
*/
|
|
15
|
-
function vercelStegaDecode(
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
15
|
+
function vercelStegaDecode(source) {
|
|
16
|
+
const matches = source.match(exports.VERCEL_STEGA_REGEX);
|
|
17
|
+
if (!matches)
|
|
18
18
|
return;
|
|
19
|
-
return decode(
|
|
19
|
+
return decode(matches[0], true)[0];
|
|
20
20
|
}
|
|
21
21
|
exports.vercelStegaDecode = vercelStegaDecode;
|
|
22
|
-
|
|
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;
|
|
23
36
|
const encoded = Array.from(encodedString);
|
|
24
37
|
if (encoded.length % 2) {
|
|
25
38
|
throw new Error(`Invalid encoded text length. Expected length to be even, received: ${encoded.length}`);
|
|
@@ -29,5 +42,24 @@ function decode(encodedString) {
|
|
|
29
42
|
const hex = `${REVERSE_HEX_DIGIT_MAP[encoded[i * 2].codePointAt(0)]}${REVERSE_HEX_DIGIT_MAP[encoded[i * 2 + 1].codePointAt(0)]}`;
|
|
30
43
|
chars.unshift(String.fromCharCode(parseInt(hex, 16)));
|
|
31
44
|
}
|
|
32
|
-
|
|
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;
|
|
33
65
|
}
|
package/dist/decode.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export declare const VERCEL_STEGA_REGEX: RegExp;
|
|
2
2
|
/**
|
|
3
|
-
* Decodes
|
|
4
|
-
* @param
|
|
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
5
|
* @returns The decoded JSON value
|
|
6
6
|
*/
|
|
7
|
-
export declare function vercelStegaDecode<T>(
|
|
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/esm/decode.js
CHANGED
|
@@ -5,17 +5,29 @@ const HEX_CHARS = `${Object.values(HEX_DIGIT_MAP)
|
|
|
5
5
|
.join('')}`;
|
|
6
6
|
export const VERCEL_STEGA_REGEX = new RegExp(`(?:[${HEX_CHARS}]{2})+`, 'gu');
|
|
7
7
|
/**
|
|
8
|
-
* Decodes
|
|
9
|
-
* @param
|
|
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
10
|
* @returns The decoded JSON value
|
|
11
11
|
*/
|
|
12
|
-
export function vercelStegaDecode(
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
12
|
+
export function vercelStegaDecode(source) {
|
|
13
|
+
const matches = source.match(VERCEL_STEGA_REGEX);
|
|
14
|
+
if (!matches)
|
|
15
15
|
return;
|
|
16
|
-
return decode(
|
|
16
|
+
return decode(matches[0], true)[0];
|
|
17
17
|
}
|
|
18
|
-
|
|
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;
|
|
19
31
|
const encoded = Array.from(encodedString);
|
|
20
32
|
if (encoded.length % 2) {
|
|
21
33
|
throw new Error(`Invalid encoded text length. Expected length to be even, received: ${encoded.length}`);
|
|
@@ -25,5 +37,24 @@ function decode(encodedString) {
|
|
|
25
37
|
const hex = `${REVERSE_HEX_DIGIT_MAP[encoded[i * 2].codePointAt(0)]}${REVERSE_HEX_DIGIT_MAP[encoded[i * 2 + 1].codePointAt(0)]}`;
|
|
26
38
|
chars.unshift(String.fromCharCode(parseInt(hex, 16)));
|
|
27
39
|
}
|
|
28
|
-
|
|
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;
|
|
29
60
|
}
|