dereference-json-schema
Advanced tools
+4
-1
@@ -5,3 +5,6 @@ /** | ||
| * https://github.com/lukeed/klona/blob/master/license | ||
| * | ||
| * Extended with circular reference tracking to support | ||
| * dereferenced OpenAPI schemas that contain self-referencing types. | ||
| */ | ||
| export declare function klona<T>(val: T): T; | ||
| export declare function klona<T>(val: T, seen?: Map<unknown, unknown>): T; |
+12
-4
@@ -5,2 +5,5 @@ /** | ||
| * https://github.com/lukeed/klona/blob/master/license | ||
| * | ||
| * Extended with circular reference tracking to support | ||
| * dereferenced OpenAPI schemas that contain self-referencing types. | ||
| */ "use strict"; | ||
@@ -16,15 +19,20 @@ Object.defineProperty(exports, "__esModule", { | ||
| }); | ||
| function klona(val) { | ||
| function klona(val, seen) { | ||
| if (!seen) seen = new Map(); | ||
| var index, out, tmp; | ||
| if (Array.isArray(val)) { | ||
| if (seen.has(val)) return seen.get(val); | ||
| out = Array(index = val.length); | ||
| while(index--)out[index] = (tmp = val[index]) && typeof tmp === "object" ? klona(tmp) : tmp; | ||
| seen.set(val, out); | ||
| while(index--)out[index] = (tmp = val[index]) && typeof tmp === "object" ? klona(tmp, seen) : tmp; | ||
| return out; | ||
| } | ||
| if (Object.prototype.toString.call(val) === "[object Object]") { | ||
| if (seen.has(val)) return seen.get(val); | ||
| out = {}; // null | ||
| seen.set(val, out); | ||
| for(index in val){ | ||
| if (index === "__proto__") { | ||
| Object.defineProperty(out, index, { | ||
| value: klona(val[index]), | ||
| value: klona(val[index], seen), | ||
| configurable: true, | ||
@@ -35,3 +43,3 @@ enumerable: true, | ||
| } else { | ||
| out[index] = (tmp = val[index]) && typeof tmp === "object" ? klona(tmp) : tmp; | ||
| out[index] = (tmp = val[index]) && typeof tmp === "object" ? klona(tmp, seen) : tmp; | ||
| } | ||
@@ -38,0 +46,0 @@ } |
+1
-1
| { | ||
| "name": "dereference-json-schema", | ||
| "version": "0.2.1", | ||
| "version": "0.2.2", | ||
| "description": "Dereference $ref pointers in JSONSchema or OpenAPI documents.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
10869
4.79%202
5.76%