Skip to content

Commit

Permalink
add addProps and setProps for adding/setting properties of an object,…
Browse files Browse the repository at this point in the history
… respectively
  • Loading branch information
marcuswestin committed May 8, 2013
1 parent 5765b72 commit ccbb970
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions addProps.js
@@ -0,0 +1,12 @@
var each = require('./each')
var copy = require('./copy')

module.exports = function addProps(target, addPropsIfNotExist) {
var result = copy(target)
each(addPropsIfNotExist, function(val, key) {
if (result[key] == undefined) {
result[key] = addPropsIfNotExist[key]
}
})
return result
}
10 changes: 10 additions & 0 deletions setProps.js
@@ -0,0 +1,10 @@
var each = require('./each')
var copy = require('./copy')

module.exports = function setProps(target, overwriteProps) {
var result = copy(target)
each(overwriteProps, function(val, key) {
result[key] = overwriteProps[key]
})
return result
}

0 comments on commit ccbb970

Please sign in to comment.