UltimateExtend
Extends target with other object's properties. Works like 'extend' module, but has several updates:
- First argument can be of type Boolean and also UltimateExtend.config ( defines how extend works )
- If objects to extend from are Promises or contain promises in properties you can use Extend.promise instead of Extend. Then it will return promise of Extended object.
Installation
# version 2.x ( alpha ) npm install ultimate-extend --save # version 1.x ( stable ) npm install ultimate-extend@1.0.1 --save
OLD Readme v1.0.1 - for v2.x see tests TODO: Update this ReadMe
Usage:
// UltimateExtend( [{config|Boolean,ExtendConfig}, ]{target|Object,Function}, ...{options|Object,Function} ) => {Object} // UltimateExtend.outer( [{config|Boolean,ExtendConfig}, ] ...{options|Object,Function} ) => {Object} // UltimateExtend.promise( [{config|Boolean,ExtendConfig}, ]{target|Object,Function}, ...{options|Object,Function} ) => {Promise{Object}} // UltimateExtend.config( {config|Object} ) => {ExtendConfig} /* --------------------------------- Extend --------------------------------- */ var Extend = ; /* ------------ Simple usage ------------- */var target = {} a = a: a: '1' b = a: a: 2 b: 2 ; ; // working as expected console; // => { a: { a: [ 2 ], b: 2 } } /* ------------ Advanced usage ------------- */ var config = Extend; var target = {}; // renew target; a, b are taken from example above ; // now all arrays are concatenated instead of extending console; // => { a: { a: [ '1', 2 ], b: 2 } } /* --------------------------------- Extend.promise --------------------------------- */ var Extend = ; var target = {} a = a: a: Promise b = a: a: 2 b: ; Extend ; /* --------------------------------- Extend.outer --------------------------------- */ // Extend.outer extends two variables as if they were in extending objectsvar Extend = ; var config = Extend; var a = 0 1 b = 2; Extend 0 1 2 outer 0 1 2 /* --------------------------------- Extend.config --------------------------------- */ // Extend.config can be produced from other configs using config.newConfig( configObj )// to execute method from origin ( parent ) config use config.callOrigin( ...{ same arguments } )// config.callOrigin() - here 3rd argument will always be replaced with config which called this method var Extend = ; var config = Extend; var newConfig = config; console; // { a: 4 }