包详细信息

object-path-set

skratchdot936MIT1.0.2

set values in javascript objects by specifying a path

object, path, helper, deep

自述文件

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 --save 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

Contributors

Thanks goes to these wonderful people (emoji key):



💻 📖

This project follows the all-contributors specification. Contributions of any kind welcome!

License

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

更新日志

1.0.2 (2022-01-30)

  • fix new prototype pollution vulnerability (2d67a71)

1.0.1 (2020-07-25)

  • add prettier and npm run build (1f34461)
  • adding contributors (5bf6e83)
  • Bump eslint from 4.18.1 to 4.18.2 (1756583)
  • fix prototype pollution vulnerability (55f06d7)
  • formatting (577f529)
  • rename tonic to runkit (9c2f1ea)
  • small readme tweaks (9750b7a)
  • travis runs node 6+ (ac1969b)
  • update libs (a990186)
  • update travis config (9c5a14e)
  • updating changelog and changelog generator (216d2e7)
  • updating libs and moving to jest (2ac8e26)
  • use prettier on markdown files (d43fa07)

1.0.0 (2016-09-10)

  • add support for array paths. (0c0694e)
  • adding npm run watch (c631f34)
  • adding CHANGELOG.md (8567c15)
  • bumping version and publishing (0de8ede)
  • updating changelog (ca6b3de)
  • updating devDependency versions (96b8b9d)
  • using npm-scripts instead of gulp (c8a691a)

0.0.2 (2015-11-20)

  • adding mocha and test coverage (8b5ac54)

0.0.1 (2014-09-15)