Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d65c92b
commit 91c87e3
Showing
1 changed file
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,57 @@ | ||
/*! | ||
* tea-extend | ||
* Copyright(c) 2012 Jake Luer <jake@qualiancy.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
exports.version = '0.0.0'; | ||
/** | ||
* ### extend (destination, source, ...) | ||
* | ||
* For each source, shallow merge its key/values to the | ||
* destinatino. Sources are read in order, meaning the same | ||
* key in a later source will overwrite the key's value earlier | ||
* set. | ||
* | ||
* ```js | ||
* var extend = require('tea-extend'); | ||
* | ||
* // sample objects | ||
* var a = { hello: 'world' } | ||
* , b = { speak: 'loudly' }; | ||
* | ||
* // change a | ||
* extend(a, b); | ||
* | ||
* // shallow clone to c | ||
* var c = extend({}, a); | ||
* ``` | ||
* | ||
* @param {Object} destination | ||
* @param {Object} sources ... | ||
* @return {Object} destination extended | ||
* @api public | ||
*/ | ||
|
||
module.exports = function () { | ||
var args = [].slice.call(arguments, 0) | ||
, res = args[0]; | ||
|
||
for (var i = 1; i < args.length; i++) { | ||
extend(res, args[i]); | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
/*! | ||
* Actually extend | ||
*/ | ||
|
||
function extend (a, b) { | ||
if (a && b) { | ||
for (var key in b) { | ||
a[key] = b[key]; | ||
} | ||
} | ||
return a; | ||
}; |