xtend
Advanced tools
Comparing version 1.0.2 to 1.0.3
16
index.js
@@ -1,17 +0,15 @@ | ||
var slice = Array.prototype.slice | ||
module.exports = extend | ||
function extend(target) { | ||
slice.call(arguments, 1).forEach(addPropertiesToSource) | ||
return target | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i], | ||
keys = Object.keys(source) | ||
function addPropertiesToSource(source) { | ||
Object.getOwnPropertyNames(source).forEach(addPropertyToSource) | ||
function addPropertyToSource(name) { | ||
for (var j = 0; j < keys.length; j++) { | ||
var name = keys[j] | ||
target[name] = source[name] | ||
} | ||
} | ||
return target | ||
} |
{ | ||
"name": "xtend", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "extend like a boss", | ||
@@ -16,2 +16,5 @@ "keywords": [], | ||
"name": "Jake Verbaten" | ||
}, | ||
{ | ||
"name": "Matt Esch" | ||
} | ||
@@ -18,0 +21,0 @@ ], |
# xtend | ||
extend like a boss | ||
Extend like a boss | ||
## Example | ||
xtend is a basic utility library which allows you to extend an object by appending all of the properties from each object in a list. When there are identical properties, the right-most property takes presedence. | ||
## Examples | ||
Basic usage: | ||
var extend = require('xtend'), | ||
a = { | ||
'I': 'am' | ||
}, | ||
b = { | ||
'a': 'boss' | ||
}; | ||
extend(a, b); | ||
console.log('I ', a.I, ' a ', a.a); | ||
Extend with multiple objects: | ||
var extend = require('xtend'), | ||
a = { | ||
'w': 'I' | ||
}, | ||
b = { | ||
'x': 'am' | ||
}, | ||
c = { | ||
'y': 'a' | ||
}, | ||
d = { | ||
'z': 'boss' | ||
} | ||
boss = extend({}, a, b, c, d); | ||
console.log(boss.w, ' ', boss.x, ' ', boss.y, ' ', boss.z); | ||
Right-most precendence: | ||
var extend = require("xtend"), | ||
a = { | ||
"I": "am" | ||
"p": 1 | ||
}, | ||
b = { | ||
"a": "boss" | ||
"p": 2 | ||
} | ||
c = { | ||
"p": 3 | ||
}, | ||
var boss = extend({}, a, b) | ||
boss = extend({}, a, b, c); | ||
console.log("I ", boss.I, " a ", boss.a) | ||
console.log(boss.p); // Logs 3 | ||
## MIT Licenced |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4145
7
31
60
1