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

Function cloneDeep

lib/utils.js:130–149  ·  view source on GitHub ↗
(obj, onlyPlain)

Source from the content-addressed store, hash-verified

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

Callers 2

mapWhereFieldNamesFunction · 0.85
addConstraintMethod · 0.85

Calls 1

cloneMethod · 0.80

Tested by

no test coverage detected