(obj, onlyPlain)
| 128 | exports.formatNamedParameters = formatNamedParameters; |
| 129 | |
| 130 | function 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 | } |
| 150 | exports.cloneDeep = cloneDeep; |
| 151 | |
| 152 | /* Expand and normalize finder options */ |
no test coverage detected