@n8n/utils 1.40.0 → 1.41.0
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.
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/json/to-json-value.ts
|
|
3
|
+
/**
|
|
4
|
+
* Recursively converts an arbitrary value into a JSON-safe representation.
|
|
5
|
+
*
|
|
6
|
+
* Handles `Buffer`, `Date`, `Error`, `bigint`, circular references, and
|
|
7
|
+
* non-finite numbers (`NaN`, `Infinity`). Values that have no JSON
|
|
8
|
+
* representation (`undefined`, functions, symbols) become `null`.
|
|
9
|
+
*/
|
|
10
|
+
function toJsonValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
11
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
12
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
13
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol") return null;
|
|
14
|
+
if (typeof value === "bigint") return value.toString();
|
|
15
|
+
if (Buffer.isBuffer(value)) return value.toString();
|
|
16
|
+
if (value instanceof Date) return value.toISOString();
|
|
17
|
+
if (value instanceof Error) return {
|
|
18
|
+
name: value.name,
|
|
19
|
+
message: value.message
|
|
20
|
+
};
|
|
21
|
+
if (Array.isArray(value)) return value.map((entry) => toJsonValue(entry, seen));
|
|
22
|
+
if (typeof value === "object") {
|
|
23
|
+
if (seen.has(value)) return "[Circular]";
|
|
24
|
+
seen.add(value);
|
|
25
|
+
const result = {};
|
|
26
|
+
for (const [key, entryValue] of Object.entries(value)) Object.defineProperty(result, key, {
|
|
27
|
+
value: toJsonValue(entryValue, seen),
|
|
28
|
+
enumerable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
configurable: true
|
|
31
|
+
});
|
|
32
|
+
seen.delete(value);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.toJsonValue = toJsonValue;
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=to-json-value.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/json/to-json-value.d.ts
|
|
2
|
+
type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
|
3
|
+
type JSONObject = {
|
|
4
|
+
[key: string]: JSONValue | undefined;
|
|
5
|
+
};
|
|
6
|
+
type JSONArray = JSONValue[];
|
|
7
|
+
declare function toJsonValue(value: unknown, seen?: WeakSet<object>): JSONValue;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { JSONArray, JSONObject, JSONValue, toJsonValue };
|
|
10
|
+
//# sourceMappingURL=to-json-value.d.cts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/json/to-json-value.d.ts
|
|
2
|
+
type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
|
3
|
+
type JSONObject = {
|
|
4
|
+
[key: string]: JSONValue | undefined;
|
|
5
|
+
};
|
|
6
|
+
type JSONArray = JSONValue[];
|
|
7
|
+
declare function toJsonValue(value: unknown, seen?: WeakSet<object>): JSONValue;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { JSONArray, JSONObject, JSONValue, toJsonValue };
|
|
10
|
+
//# sourceMappingURL=to-json-value.d.mts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/json/to-json-value.ts
|
|
2
|
+
/**
|
|
3
|
+
* Recursively converts an arbitrary value into a JSON-safe representation.
|
|
4
|
+
*
|
|
5
|
+
* Handles `Buffer`, `Date`, `Error`, `bigint`, circular references, and
|
|
6
|
+
* non-finite numbers (`NaN`, `Infinity`). Values that have no JSON
|
|
7
|
+
* representation (`undefined`, functions, symbols) become `null`.
|
|
8
|
+
*/
|
|
9
|
+
function toJsonValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
10
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
11
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
12
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol") return null;
|
|
13
|
+
if (typeof value === "bigint") return value.toString();
|
|
14
|
+
if (Buffer.isBuffer(value)) return value.toString();
|
|
15
|
+
if (value instanceof Date) return value.toISOString();
|
|
16
|
+
if (value instanceof Error) return {
|
|
17
|
+
name: value.name,
|
|
18
|
+
message: value.message
|
|
19
|
+
};
|
|
20
|
+
if (Array.isArray(value)) return value.map((entry) => toJsonValue(entry, seen));
|
|
21
|
+
if (typeof value === "object") {
|
|
22
|
+
if (seen.has(value)) return "[Circular]";
|
|
23
|
+
seen.add(value);
|
|
24
|
+
const result = {};
|
|
25
|
+
for (const [key, entryValue] of Object.entries(value)) Object.defineProperty(result, key, {
|
|
26
|
+
value: toJsonValue(entryValue, seen),
|
|
27
|
+
enumerable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
configurable: true
|
|
30
|
+
});
|
|
31
|
+
seen.delete(value);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { toJsonValue };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=to-json-value.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n8n/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.41.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"LICENSE.md",
|
|
8
|
+
"LICENSE_EE.md"
|
|
9
9
|
],
|
|
10
10
|
"exports": {
|
|
11
11
|
"./dist/*": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"vite": "^8.0.2",
|
|
39
39
|
"vitest": "^4.1.9",
|
|
40
40
|
"@n8n/typescript-config": "1.9.0",
|
|
41
|
-
"@n8n/
|
|
42
|
-
"@n8n/
|
|
41
|
+
"@n8n/eslint-config": "0.0.1",
|
|
42
|
+
"@n8n/vitest-config": "1.19.0"
|
|
43
43
|
},
|
|
44
44
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
45
45
|
"homepage": "https://n8n.io",
|