Skip to content

Commit fd11b26

Browse files
authored
Merge pull request #44 from lucasfcosta/return-obj-from-set
feat: setPathValue returns the object in which the value was set. Closes #6
2 parents 35c4f04 + 352dd71 commit fd11b26

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ function getPathValue(obj, path) {
280280
function setPathValue(obj, path, val) {
281281
var parsed = parsePath(path);
282282
internalSetPathValue(obj, val, parsed);
283+
return obj;
283284
}
284285

285286
module.exports = {

test/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,10 @@ describe('setPathValue', function () {
216216
assert(obj.hello[1] === 2);
217217
assert(obj.hello[2] === 3);
218218
});
219+
220+
it('returns the object in which the value was set', function () {
221+
var obj = { hello: [ 1, 2, 4 ] };
222+
var valueReturned = pathval.setPathValue(obj, 'hello[2]', 3);
223+
assert(obj === valueReturned);
224+
});
219225
});

0 commit comments

Comments
 (0)