Deep extend with customizable behavior for Node.js.
Extedify is a lightweight wrapper over lodash's _.merge (like a deep _.extend) with customizable handling of arrays, booleans, numbers and strings.
By default, extedify will behave exactly like lodash's _.merge.
npm install extendifyvar extendify = require('extendify');
myExtend = extendify({
// options
});inPlace– Override the 'source' with the result?truedefaultfalse
isDeep– Use deep extend?truedefaultfalse
arrays– How to handle arrays?'replace''concat''merge'default'or''and'
booleans– How to handle booleans?'replace'default'concat''or''and'
numbers– How to handle numbers?'replace'default'concat''or''and'
strings– How to handle strings?'replace'default'concat''or''and'
Let's get an _.extend function that
- is immutable to it's arguments,
- replaces arrays,
- supports nested objects (also known as deep extends).
myExtend = extendify({
inPlace: false,
arrays : 'replace'
});
object1 = {
a:{
list: [1, 2]
},
b: 4
};
object2 = {
a:{
list: [3]
}
};myExtend(object1, object2); will give you the following. obj1 === res is false.
{
a: {
list: [3]
},
b: 4
}
More examples are available in the 'examples.js' file.
Your feedback is welcome, email me at reshef.shai@gmail.com.