Skip to content

Update or set nested values and any intermediaries with dot notation (`'a.b.c'`) paths.

License

Notifications You must be signed in to change notification settings

doowb/upsert-value

Repository files navigation

upsert-value NPM version Build Status

Update or set nested values and any intermediaries with dot notation ('a.b.c') paths.

Install with npm

$ npm i upsert-value --save

Usage

var upsert = require('upsert-value');

API

Update or set a value on the given object with the given key path.

Params

  • obj {Object}: Object to update/set.
  • path {String}: Key path to update/set.
  • value {*}: Value to update/set.
  • returns {Object}: Update object.

Example

var obj = {};
upsert(obj, 'a.b.c', 'foo');
//=> {a: {b: {c: 'foo'}}}

Related projects

  • has-own-deep: Returns true if an object has an own, nested property using dot notation paths ('a.b.c').
  • put-value: Update only existing values from an object, works with dot notation paths like a.b.c and… more
  • set-value: Create nested values and any intermediaries using dot notation ('a.b.c') paths.

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Brian Woodward

License

Copyright © 2015 Brian Woodward Released under the MIT license.


This file was generated by verb-cli on July 09, 2015.

About

Update or set nested values and any intermediaries with dot notation (`'a.b.c'`) paths.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  
  •  

Packages

No packages published