@vercel/stega
Advanced tools
Comparing version 0.0.3 to 0.0.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.vercelStegaDecode = exports.VERCEL_STEGA_REGEX = void 0; | ||
exports.vercelStegaDecodeAll = exports.vercelStegaDecode = exports.VERCEL_STEGA_REGEX = void 0; | ||
const map_1 = require("./map"); | ||
@@ -11,14 +11,27 @@ const REVERSE_HEX_DIGIT_MAP = Object.fromEntries(Object.entries(map_1.HEX_DIGIT_MAP).map((x) => x.reverse())); | ||
/** | ||
* Decodes a hidden string back into its original value | ||
* @param encoded - The encoded (hidden) string | ||
* Decodes the first hidden string that's found in the source string back into its original value | ||
* @param source - The source string with encoded data | ||
* @returns The decoded JSON value | ||
*/ | ||
function vercelStegaDecode(encoded) { | ||
const match = encoded.match(exports.VERCEL_STEGA_REGEX); | ||
if (!match) | ||
function vercelStegaDecode(source) { | ||
const matches = source.match(exports.VERCEL_STEGA_REGEX); | ||
if (!matches) | ||
return; | ||
return decode(match[0]); | ||
return decode(matches[0], true)[0]; | ||
} | ||
exports.vercelStegaDecode = vercelStegaDecode; | ||
function decode(encodedString) { | ||
/** | ||
* Decodes every hidden string that's found in the source string back into their original values | ||
* @param source - The source string with encoded data | ||
* @returns The decoded JSON values | ||
*/ | ||
function vercelStegaDecodeAll(source) { | ||
const matches = source.match(exports.VERCEL_STEGA_REGEX); | ||
if (!matches) | ||
return; | ||
return matches.map((match) => decode(match)).flat(); | ||
} | ||
exports.vercelStegaDecodeAll = vercelStegaDecodeAll; | ||
function decode(encodedString, firstOnly = false) { | ||
var _a; | ||
const encoded = Array.from(encodedString); | ||
@@ -33,3 +46,22 @@ if (encoded.length % 2) { | ||
} | ||
return JSON.parse(chars.join('')); | ||
const results = []; | ||
const queue = [chars.join('')]; | ||
let breakLimit = 10; | ||
while (queue.length) { | ||
const string = queue.shift(); | ||
try { | ||
results.push(JSON.parse(string)); | ||
if (firstOnly) | ||
return results; | ||
} | ||
catch (error) { | ||
if (!breakLimit--) | ||
throw error; | ||
const position = +((_a = error.message.match(/\sposition\s(\d+)$/)) === null || _a === void 0 ? void 0 : _a[1]); | ||
if (!position) | ||
throw error; | ||
queue.unshift(string.substring(0, position), string.substring(position)); | ||
} | ||
} | ||
return results; | ||
} |
export declare const VERCEL_STEGA_REGEX: RegExp; | ||
/** | ||
* Decodes a hidden string back into its original value | ||
* @param encoded - The encoded (hidden) string | ||
* Decodes the first hidden string that's found in the source string back into its original value | ||
* @param source - The source string with encoded data | ||
* @returns The decoded JSON value | ||
*/ | ||
export declare function vercelStegaDecode<T>(encoded: string): T | undefined; | ||
export declare function vercelStegaDecode<T>(source: string): T | undefined; | ||
/** | ||
* Decodes every hidden string that's found in the source string back into their original values | ||
* @param source - The source string with encoded data | ||
* @returns The decoded JSON values | ||
*/ | ||
export declare function vercelStegaDecodeAll<T>(source: string): T[]; |
@@ -8,13 +8,25 @@ import { HEX_DIGIT_MAP } from './map'; | ||
/** | ||
* Decodes a hidden string back into its original value | ||
* @param encoded - The encoded (hidden) string | ||
* Decodes the first hidden string that's found in the source string back into its original value | ||
* @param source - The source string with encoded data | ||
* @returns The decoded JSON value | ||
*/ | ||
export function vercelStegaDecode(encoded) { | ||
const match = encoded.match(VERCEL_STEGA_REGEX); | ||
if (!match) | ||
export function vercelStegaDecode(source) { | ||
const matches = source.match(VERCEL_STEGA_REGEX); | ||
if (!matches) | ||
return; | ||
return decode(match[0]); | ||
return decode(matches[0], true)[0]; | ||
} | ||
function decode(encodedString) { | ||
/** | ||
* Decodes every hidden string that's found in the source string back into their original values | ||
* @param source - The source string with encoded data | ||
* @returns The decoded JSON values | ||
*/ | ||
export function vercelStegaDecodeAll(source) { | ||
const matches = source.match(VERCEL_STEGA_REGEX); | ||
if (!matches) | ||
return; | ||
return matches.map((match) => decode(match)).flat(); | ||
} | ||
function decode(encodedString, firstOnly = false) { | ||
var _a; | ||
const encoded = Array.from(encodedString); | ||
@@ -29,3 +41,22 @@ if (encoded.length % 2) { | ||
} | ||
return JSON.parse(chars.join('')); | ||
const results = []; | ||
const queue = [chars.join('')]; | ||
let breakLimit = 10; | ||
while (queue.length) { | ||
const string = queue.shift(); | ||
try { | ||
results.push(JSON.parse(string)); | ||
if (firstOnly) | ||
return results; | ||
} | ||
catch (error) { | ||
if (!breakLimit--) | ||
throw error; | ||
const position = +((_a = error.message.match(/\sposition\s(\d+)$/)) === null || _a === void 0 ? void 0 : _a[1]); | ||
if (!position) | ||
throw error; | ||
queue.unshift(string.substring(0, position), string.substring(position)); | ||
} | ||
} | ||
return results; | ||
} |
{ | ||
"name": "@vercel/stega", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Utilities for steganography", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
27184
316
0