Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.
The set-value npm package is a utility for setting deeply nested values within an object using dot-path notation or by providing a path array. It is useful for updating values in a mutable way without directly accessing properties, especially when dealing with complex or deeply nested objects.
Set nested values using dot-path
This feature allows you to set a value at a nested path within an object using a string dot-path notation.
const setValue = require('set-value');
const obj = {};
setValue(obj, 'a.b.c', 'value');
console.log(obj); //=> { a: { b: { c: 'value' } } }
Set nested values using array-path
This feature allows you to set a value at a nested path within an object using an array to describe the path.
const setValue = require('set-value');
const obj = {};
setValue(obj, ['a', 'b', 'c'], 'value');
console.log(obj); //=> { a: { b: { c: 'value' } } }
Set multiple values
This feature allows you to set multiple values at different paths within the same object.
const setValue = require('set-value');
const obj = {};
setValue(obj, 'a.b.c', 'value1');
setValue(obj, 'x.y.z', 'value2');
console.log(obj); //=> { a: { b: { c: 'value1' } }, x: { y: { z: 'value2' } } }
lodash.set is a method from the Lodash library that performs a similar function to set-value. It allows setting values at a given path of an object tree. Lodash is a more extensive utility library, and lodash.set is just one of its many functions.
dot-prop is another npm package that allows you to get, set, or delete properties from a nested object using dot-path notation. It is similar to set-value but also provides methods for getting and deleting properties.
deepdash is an extension for Lodash that adds deep object manipulation capabilities. It provides methods for deep setting, getting, and many other operations on nested objects. It is more feature-rich compared to set-value, which focuses solely on setting values.
Create nested values and any intermediaries using dot notation (
'a.b.c'
) paths.
Install with npm
$ npm i set-value --save
var set = require('set-value');
var obj = {};
set(obj, 'a.b.c', 'd');
console.log(obj);
//=> {a: {b: c: 'd'}}
a.b.c
) to get a nested value from an object. | homepage'a.b.c'
) paths. | homepageInstall dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb on December 10, 2015.
FAQs
Set nested properties on an object using dot notation.
The npm package set-value receives a total of 4,936,495 weekly downloads. As such, set-value popularity was classified as popular.
We found that set-value demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.