UNPKG

gatsby-source-sanity

Version:

Gatsby source plugin for building websites using Sanity.io as a backend.

33 lines 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); function copyValue(value, maxDepth, currentDepth) { const name = typeof value; if (name === 'string' || name === 'boolean' || name === 'number') { return value.valueOf(); } if (Array.isArray(value)) { if (currentDepth > maxDepth) { return []; } return value.map(item => copyValue(item, maxDepth, currentDepth + 1)); } if (lodash_1.isPlainObject(value)) { if (currentDepth > maxDepth) { return {}; } const copiedObject = {}; Object.keys(value).forEach(key => { const result = copyValue(value[key], maxDepth, currentDepth + 1); copiedObject[key] = result; }); return copiedObject; } throw new Error(`Unable to copy value: ${value}`); } // Deep copy any json object. Arrays or objects deeper than maxDepth return as empty [] or {} function deepCopy(value, maxDepth) { return copyValue(value, maxDepth, 1); } exports.deepCopy = deepCopy; //# sourceMappingURL=deepCopy.js.map