(obj, onlyPlain)
| 141 | exports.formatNamedParameters = formatNamedParameters; |
| 142 | |
| 143 | function 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 | } |
| 163 | exports.cloneDeep = cloneDeep; |
| 164 | |
| 165 | /* Expand and normalize finder options */ |
no test coverage detected