Skip to content

Commit

Permalink
Merge pull request #44 from lucasfcosta/return-obj-from-set
Browse files Browse the repository at this point in the history
feat: setPathValue returns the object in which the value was set. Closes #6
  • Loading branch information
keithamus authored Oct 11, 2016
2 parents 35c4f04 + 352dd71 commit fd11b26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ function getPathValue(obj, path) {
function setPathValue(obj, path, val) {
var parsed = parsePath(path);
internalSetPathValue(obj, val, parsed);
return obj;
}

module.exports = {
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,10 @@ describe('setPathValue', function () {
assert(obj.hello[1] === 2);
assert(obj.hello[2] === 3);
});

it('returns the object in which the value was set', function () {
var obj = { hello: [ 1, 2, 4 ] };
var valueReturned = pathval.setPathValue(obj, 'hello[2]', 3);
assert(obj === valueReturned);
});
});

0 comments on commit fd11b26

Please sign in to comment.