MCPcopy
hub / github.com/sequelize/sequelize / cloneDeep

Function cloneDeep

src/utils.js:143–162  ·  view source on GitHub ↗
(obj, onlyPlain)

Source from the content-addressed store, hash-verified

141exports.formatNamedParameters = formatNamedParameters;
142
143function cloneDeep(obj, onlyPlain) {
144 obj = obj || {};
145 return _.cloneDeepWith(obj, elem => {
146 // Do not try to customize cloning of arrays or POJOs
147 if (Array.isArray(elem) || _.isPlainObject(elem)) {
148 return undefined;
149 }
150
151 // If we specified to clone only plain objects & arrays, we ignore everyhing else
152 // In any case, don't clone stuff that's an object, but not a plain one - fx example sequelize models and instances
153 if (onlyPlain || typeof elem === 'object') {
154 return elem;
155 }
156
157 // Preserve special data-types like `fn` across clones. _.get() is used for checking up the prototype chain
158 if (elem && typeof elem.clone === 'function') {
159 return elem.clone();
160 }
161 });
162}
163exports.cloneDeep = cloneDeep;
164
165/* Expand and normalize finder options */

Callers 2

mapWhereFieldNamesFunction · 0.85
addConstraintMethod · 0.85

Calls 1

cloneMethod · 0.80

Tested by

no test coverage detected