UNPKG

ts-json-schema-generator

Version:

Generate JSON schema from your Typescript sources

40 lines 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const stringify = require("json-stable-stringify"); const uniqueArrayWithHash_1 = require("./uniqueArrayWithHash"); function deepMerge(a, b, concatArrays) { const typeA = typeof a; const typeB = typeof b; if (typeA === typeB && typeA === "object" && typeA !== null && a !== b) { const isArrayA = Array.isArray(a); const isArrayB = Array.isArray(b); if (isArrayA && isArrayB) { if (concatArrays) { return uniqueArrayWithHash_1.uniqueArrayWithHash(a.concat(b), stringify); } else { return b; } } else if ((isArrayA && !isArrayB) || (!isArrayA && isArrayB)) { return b; } else { const output = Object.assign({}, a); for (const key in output) { if (b.hasOwnProperty(key)) { output[key] = deepMerge(a[key], b[key], concatArrays); } } for (const key in b) { if (!a.hasOwnProperty(key)) { output[key] = b[key]; } } return output; } } return b; } exports.deepMerge = deepMerge; //# sourceMappingURL=deepMerge.js.map