🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@n8n/utils

Package Overview
Dependencies
Maintainers
5
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@n8n/utils - npm Package Compare versions

Comparing version
1.40.0
to
1.41.0
+40
dist/json/to-json-value.cjs
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/json/to-json-value.ts
/**
* Recursively converts an arbitrary value into a JSON-safe representation.
*
* Handles `Buffer`, `Date`, `Error`, `bigint`, circular references, and
* non-finite numbers (`NaN`, `Infinity`). Values that have no JSON
* representation (`undefined`, functions, symbols) become `null`.
*/
function toJsonValue(value, seen = /* @__PURE__ */ new WeakSet()) {
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
if (typeof value === "number") return Number.isFinite(value) ? value : null;
if (value === void 0 || typeof value === "function" || typeof value === "symbol") return null;
if (typeof value === "bigint") return value.toString();
if (Buffer.isBuffer(value)) return value.toString();
if (value instanceof Date) return value.toISOString();
if (value instanceof Error) return {
name: value.name,
message: value.message
};
if (Array.isArray(value)) return value.map((entry) => toJsonValue(entry, seen));
if (typeof value === "object") {
if (seen.has(value)) return "[Circular]";
seen.add(value);
const result = {};
for (const [key, entryValue] of Object.entries(value)) Object.defineProperty(result, key, {
value: toJsonValue(entryValue, seen),
enumerable: true,
writable: true,
configurable: true
});
seen.delete(value);
return result;
}
return null;
}
//#endregion
exports.toJsonValue = toJsonValue;
//# sourceMappingURL=to-json-value.cjs.map
{"version":3,"file":"to-json-value.cjs","names":[],"sources":["../../src/json/to-json-value.ts"],"sourcesContent":["export type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\n\nexport type JSONObject = {\n\t[key: string]: JSONValue | undefined;\n};\n\nexport type JSONArray = JSONValue[];\n\n/**\n * Recursively converts an arbitrary value into a JSON-safe representation.\n *\n * Handles `Buffer`, `Date`, `Error`, `bigint`, circular references, and\n * non-finite numbers (`NaN`, `Infinity`). Values that have no JSON\n * representation (`undefined`, functions, symbols) become `null`.\n */\nexport function toJsonValue(value: unknown, seen = new WeakSet<object>()): JSONValue {\n\tif (value === null || typeof value === 'string' || typeof value === 'boolean') {\n\t\treturn value;\n\t}\n\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value) ? value : null;\n\t}\n\n\tif (value === undefined || typeof value === 'function' || typeof value === 'symbol') {\n\t\treturn null;\n\t}\n\n\tif (typeof value === 'bigint') {\n\t\treturn value.toString();\n\t}\n\n\tif (Buffer.isBuffer(value)) {\n\t\treturn value.toString();\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn value.toISOString();\n\t}\n\n\tif (value instanceof Error) {\n\t\treturn {\n\t\t\tname: value.name,\n\t\t\tmessage: value.message,\n\t\t};\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.map((entry) => toJsonValue(entry, seen));\n\t}\n\n\tif (typeof value === 'object') {\n\t\tif (seen.has(value)) {\n\t\t\treturn '[Circular]';\n\t\t}\n\n\t\tseen.add(value);\n\t\tconst result: JSONObject = {};\n\t\tfor (const [key, entryValue] of Object.entries(value)) {\n\t\t\tObject.defineProperty(result, key, {\n\t\t\t\tvalue: toJsonValue(entryValue, seen),\n\t\t\t\tenumerable: true,\n\t\t\t\twritable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\tseen.delete(value);\n\t\treturn result;\n\t}\n\n\treturn null;\n}\n"],"mappings":";;;;;;;;;AAeA,SAAgB,YAAY,OAAgB,uBAAO,IAAI,QAAgB,GAAc;CACpF,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,WACnE,OAAO;CAGR,IAAI,OAAO,UAAU,UACpB,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;CAGzC,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,cAAc,OAAO,UAAU,UAC1E,OAAO;CAGR,IAAI,OAAO,UAAU,UACpB,OAAO,MAAM,SAAS;CAGvB,IAAI,OAAO,SAAS,KAAK,GACxB,OAAO,MAAM,SAAS;CAGvB,IAAI,iBAAiB,MACpB,OAAO,MAAM,YAAY;CAG1B,IAAI,iBAAiB,OACpB,OAAO;EACN,MAAM,MAAM;EACZ,SAAS,MAAM;CAChB;CAGD,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,KAAK,UAAU,YAAY,OAAO,IAAI,CAAC;CAGrD,IAAI,OAAO,UAAU,UAAU;EAC9B,IAAI,KAAK,IAAI,KAAK,GACjB,OAAO;EAGR,KAAK,IAAI,KAAK;EACd,MAAM,SAAqB,CAAC;EAC5B,KAAK,MAAM,CAAC,KAAK,eAAe,OAAO,QAAQ,KAAK,GACnD,OAAO,eAAe,QAAQ,KAAK;GAClC,OAAO,YAAY,YAAY,IAAI;GACnC,YAAY;GACZ,UAAU;GACV,cAAc;EACf,CAAC;EAEF,KAAK,OAAO,KAAK;EACjB,OAAO;CACR;CAEA,OAAO;AACR"}
//#region src/json/to-json-value.d.ts
type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
type JSONObject = {
[key: string]: JSONValue | undefined;
};
type JSONArray = JSONValue[];
declare function toJsonValue(value: unknown, seen?: WeakSet<object>): JSONValue;
//#endregion
export { JSONArray, JSONObject, JSONValue, toJsonValue };
//# sourceMappingURL=to-json-value.d.cts.map
//#region src/json/to-json-value.d.ts
type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
type JSONObject = {
[key: string]: JSONValue | undefined;
};
type JSONArray = JSONValue[];
declare function toJsonValue(value: unknown, seen?: WeakSet<object>): JSONValue;
//#endregion
export { JSONArray, JSONObject, JSONValue, toJsonValue };
//# sourceMappingURL=to-json-value.d.mts.map
//#region src/json/to-json-value.ts
/**
* Recursively converts an arbitrary value into a JSON-safe representation.
*
* Handles `Buffer`, `Date`, `Error`, `bigint`, circular references, and
* non-finite numbers (`NaN`, `Infinity`). Values that have no JSON
* representation (`undefined`, functions, symbols) become `null`.
*/
function toJsonValue(value, seen = /* @__PURE__ */ new WeakSet()) {
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
if (typeof value === "number") return Number.isFinite(value) ? value : null;
if (value === void 0 || typeof value === "function" || typeof value === "symbol") return null;
if (typeof value === "bigint") return value.toString();
if (Buffer.isBuffer(value)) return value.toString();
if (value instanceof Date) return value.toISOString();
if (value instanceof Error) return {
name: value.name,
message: value.message
};
if (Array.isArray(value)) return value.map((entry) => toJsonValue(entry, seen));
if (typeof value === "object") {
if (seen.has(value)) return "[Circular]";
seen.add(value);
const result = {};
for (const [key, entryValue] of Object.entries(value)) Object.defineProperty(result, key, {
value: toJsonValue(entryValue, seen),
enumerable: true,
writable: true,
configurable: true
});
seen.delete(value);
return result;
}
return null;
}
//#endregion
export { toJsonValue };
//# sourceMappingURL=to-json-value.mjs.map
{"version":3,"file":"to-json-value.mjs","names":[],"sources":["../../src/json/to-json-value.ts"],"sourcesContent":["export type JSONValue = null | string | number | boolean | JSONObject | JSONArray;\n\nexport type JSONObject = {\n\t[key: string]: JSONValue | undefined;\n};\n\nexport type JSONArray = JSONValue[];\n\n/**\n * Recursively converts an arbitrary value into a JSON-safe representation.\n *\n * Handles `Buffer`, `Date`, `Error`, `bigint`, circular references, and\n * non-finite numbers (`NaN`, `Infinity`). Values that have no JSON\n * representation (`undefined`, functions, symbols) become `null`.\n */\nexport function toJsonValue(value: unknown, seen = new WeakSet<object>()): JSONValue {\n\tif (value === null || typeof value === 'string' || typeof value === 'boolean') {\n\t\treturn value;\n\t}\n\n\tif (typeof value === 'number') {\n\t\treturn Number.isFinite(value) ? value : null;\n\t}\n\n\tif (value === undefined || typeof value === 'function' || typeof value === 'symbol') {\n\t\treturn null;\n\t}\n\n\tif (typeof value === 'bigint') {\n\t\treturn value.toString();\n\t}\n\n\tif (Buffer.isBuffer(value)) {\n\t\treturn value.toString();\n\t}\n\n\tif (value instanceof Date) {\n\t\treturn value.toISOString();\n\t}\n\n\tif (value instanceof Error) {\n\t\treturn {\n\t\t\tname: value.name,\n\t\t\tmessage: value.message,\n\t\t};\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.map((entry) => toJsonValue(entry, seen));\n\t}\n\n\tif (typeof value === 'object') {\n\t\tif (seen.has(value)) {\n\t\t\treturn '[Circular]';\n\t\t}\n\n\t\tseen.add(value);\n\t\tconst result: JSONObject = {};\n\t\tfor (const [key, entryValue] of Object.entries(value)) {\n\t\t\tObject.defineProperty(result, key, {\n\t\t\t\tvalue: toJsonValue(entryValue, seen),\n\t\t\t\tenumerable: true,\n\t\t\t\twritable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\tseen.delete(value);\n\t\treturn result;\n\t}\n\n\treturn null;\n}\n"],"mappings":";;;;;;;;AAeA,SAAgB,YAAY,OAAgB,uBAAO,IAAI,QAAgB,GAAc;CACpF,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,WACnE,OAAO;CAGR,IAAI,OAAO,UAAU,UACpB,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;CAGzC,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,cAAc,OAAO,UAAU,UAC1E,OAAO;CAGR,IAAI,OAAO,UAAU,UACpB,OAAO,MAAM,SAAS;CAGvB,IAAI,OAAO,SAAS,KAAK,GACxB,OAAO,MAAM,SAAS;CAGvB,IAAI,iBAAiB,MACpB,OAAO,MAAM,YAAY;CAG1B,IAAI,iBAAiB,OACpB,OAAO;EACN,MAAM,MAAM;EACZ,SAAS,MAAM;CAChB;CAGD,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,KAAK,UAAU,YAAY,OAAO,IAAI,CAAC;CAGrD,IAAI,OAAO,UAAU,UAAU;EAC9B,IAAI,KAAK,IAAI,KAAK,GACjB,OAAO;EAGR,KAAK,IAAI,KAAK;EACd,MAAM,SAAqB,CAAC;EAC5B,KAAK,MAAM,CAAC,KAAK,eAAe,OAAO,QAAQ,KAAK,GACnD,OAAO,eAAe,QAAQ,KAAK;GAClC,OAAO,YAAY,YAAY,IAAI;GACnC,YAAY;GACZ,UAAU;GACV,cAAc;EACf,CAAC;EAEF,KAAK,OAAO,KAAK;EACjB,OAAO;CACR;CAEA,OAAO;AACR"}
+5
-5
{
"name": "@n8n/utils",
"type": "module",
"version": "1.40.0",
"version": "1.41.0",
"files": [
"dist",
"LICENSE_EE.md",
"LICENSE.md"
"LICENSE.md",
"LICENSE_EE.md"
],

@@ -41,4 +41,4 @@ "exports": {

"@n8n/typescript-config": "1.9.0",
"@n8n/vitest-config": "1.19.0",
"@n8n/eslint-config": "0.0.1"
"@n8n/eslint-config": "0.0.1",
"@n8n/vitest-config": "1.19.0"
},

@@ -45,0 +45,0 @@ "license": "SEE LICENSE IN LICENSE.md",