Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add addProps and setProps for adding/setting properties of an object,…
… respectively
- Loading branch information
1 parent
5765b72
commit ccbb970
Showing
2 changed files
with
22 additions
and
0 deletions.
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 |
---|---|---|
@@ -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 | ||
} |
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 |
---|---|---|
@@ -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 | ||
} |