object-path-set
set values in javascript objects by specifying a path
Last updated 4 years ago by skratchdot .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install object-path-set 
SYNC missed versions from official npm registry.

object-path-set

NPM version Build Status Code Climate Coverage Status Dependency Status devDependency Status

NPM

Description

set values in javascript objects by specifying a path.

if the path doesn't exist yet, it will be created.

by using this library, you can help prevent the following error from occurring:

Cannot set property 'foo' of undefined

NOTE: I've re-written / used this function so many different times, I decided to publish it as a module.

Getting Started

Install the module with: npm install object-path-set

var setPath = require('object-path-set');
var obj = {foo:{bar:'baz'}};
obj = setPath(obj, 'foo.bar', 'newValue'); // result: {foo:{bar:'newValue'}}
obj = setPath(obj, 'foo.invalidKey', 'cool'); // result: {foo:{bar:'newValue',invalidKey: 'cool'}}
obj = setPath(obj, 'foo|bar', 'again', '|'); // result: {foo:{bar:'again',invalidKey: 'cool'}}

Links

License

Copyright (c) 2014 skratchdot
Licensed under the MIT license.

Current Tags

  • 1.0.0                                ...           latest (4 years ago)

3 Versions

  • 1.0.0                                ...           4 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 4
Last Month 12
Dependencies (0)
None
Dev Dependencies (7)

Copyright 2014 - 2016 © taobao.org |