-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhelpers.js
30 lines (25 loc) · 836 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const _ = require('lodash');
function cloneDeep(obj) {
obj = obj || {};
return _.cloneDeepWith(obj, (elem) => {
// Do not try to customize cloning of arrays or POJOs
if (Array.isArray(elem) || _.isPlainObject(elem)) {
return undefined;
}
// Don't clone stuff that's an object, but not a plain one - fx example sequelize models and instances
if (typeof elem === 'object') {
return elem;
}
// Preserve special data-types like `fn` across clones. _.get() is used for checking up the prototype chain
if (elem && typeof elem.clone === 'function') {
return elem.clone();
}
});
}
function warnDeprecated(message) {
console.warn(`DEPRECATED: ${message}`);
}
module.exports = {
cloneDeep,
warnDeprecated,
};