Gathering detailed insights and metrics for set-value
Gathering detailed insights and metrics for set-value
Gathering detailed insights and metrics for set-value
Gathering detailed insights and metrics for set-value
union-value
Set an array of unique values as the property of an object. Supports setting deeply nested properties using using object-paths/dot notation.
is-set
Is this value a JS Set? This module works cross-realm/iframe, and despite ES6 @@toStringTag.
is-accessor-descriptor
Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
is-data-descriptor
Returns true if a value has the characteristics of a valid JavaScript data descriptor.
Set nested properties on an object using dot-notation.
npm install set-value
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.5
Supply Chain
100
Quality
77.9
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
5,479,932,119
Last Day
945,521
Last Week
13,448,236
Last Month
58,176,132
Last Year
649,403,406
MIT License
278 Stars
105 Commits
40 Forks
10 Watchers
3 Branches
11 Contributors
Updated on May 16, 2025
Minified
Minified + Gzipped
Latest Version
4.1.0
Package Id
set-value@4.1.0
Size
6.63 kB
NPM Version
7.22.0
Node Version
16.4.2
Published on
Sep 12, 2021
Cumulative downloads
Total Downloads
Last Day
-0.4%
945,521
Compared to previous day
Last Week
-7.1%
13,448,236
Compared to previous week
Last Month
2.3%
58,176,132
Compared to previous month
Last Year
-15.4%
649,403,406
Compared to previous year
2
3
Set nested properties on an object using dot notation.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm (requires Node.js >=11.0):
1$ npm install --save set-value
Please update to version 3.0.1 or later, a critical bug was fixed in that version.
1const set = require('set-value'); 2 3const obj = {}; 4set(obj, 'a.b.c', 'd'); 5 6console.log(obj); 7//=> { a: { b: { c: 'd' } } }
Signature:
1set(object, property_path, value[, options]);
object
{Object}: The object to set value
onpath
{String|Symbol|Array}: The path of the property to set.value
{any}: The value to set on obj[prop]
options
{Object}: See all available optionsYou may pass a string, symbol, or array of strings or symbols. By default, when a string is passed this library will split the string on .
or a custom separator It's useful to pass an array
Escaping with backslashes
Prevent set-value from splitting on a dot by prefixing it with backslashes:
1console.log(set({}, 'a\\.b.c', 'd')); 2//=> { 'a.b': { c: 'd' } } 3 4console.log(set({}, 'a\\.b\\.c', 'd')); 5//=> { 'a.b.c': 'd' }
Do not split properties that include a /
. By default, set-value assumes that properties with a /
are not intended to be split. This option allows you to disable default behavior.
Note that this option cannot be used if options.separator
is set to /
.
Type: boolean
Default: true
Example
1console.log(set({}, 'https://github.com', true)); 2//=> { 'https://github.com': true } 3 4console.log(set({}, 'https://github.com', true, { preservePaths: false })); 5//=> { 'https://github': { com: true } }
Custom separator to use for splitting object paths.
Type: string
Default: .
Example
1console.log(set(obj, 'auth/userpass/users/bob', '*****', { separator: '/' })); 2//=> { auth: { userpass: { users: { bob: '*****' } } } }
Custom .split()
function to use.
Allows you to update plain object values, instead of overwriting them.
Type: boolean|function
- A custom merge
function may be defined if you need to deep merge. Otherwise, when merge
is true
, a shallow merge will be performed by Object.assign()
.
Default: undefined
Example
1const obj = { foo: { bar: { baz: 'qux' } } }; 2set(obj, 'foo.bar.fez', 'zzz', { merge: true }); 3//=> { foo: { bar: { baz: 'qux', fez: 'zzz' } } }
Benchmarks were run on a MacBook Pro 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3.
# deep (194 bytes)
deep-object x 823,287 ops/sec ±1.00% (90 runs sampled)
deep-property x 1,787,990 ops/sec ±0.82% (92 runs sampled)
deephas x 840,700 ops/sec ±0.95% (93 runs sampled)
dot-prop x 1,249,663 ops/sec ±0.89% (90 runs sampled)
dot2val x 2,067,212 ops/sec ±1.08% (91 runs sampled)
es5-dot-prop x 1,668,806 ops/sec ±0.92% (92 runs sampled)
lodash-set x 1,286,725 ops/sec ±0.82% (90 runs sampled)
object-path-set x 1,261,242 ops/sec ±1.63% (90 runs sampled)
object-set x 285,369 ops/sec ±0.91% (90 runs sampled)
set-value x 2,076,931 ops/sec ±0.86% (93 runs sampled)
fastest is set-value, dot2val (by 203% avg)
# medium (98 bytes)
deep-object x 5,811,161 ops/sec ±1.12% (90 runs sampled)
deep-property x 4,075,885 ops/sec ±0.91% (90 runs sampled)
deephas x 1,508,136 ops/sec ±0.82% (92 runs sampled)
dot-prop x 2,809,838 ops/sec ±1.16% (87 runs sampled)
dot2val x 4,600,890 ops/sec ±0.76% (91 runs sampled)
es5-dot-prop x 3,263,790 ops/sec ±0.97% (91 runs sampled)
lodash-set x 3,486,628 ops/sec ±1.20% (90 runs sampled)
object-path-set x 3,729,018 ops/sec ±0.90% (92 runs sampled)
object-set x 973,961 ops/sec ±0.80% (92 runs sampled)
set-value x 6,941,474 ops/sec ±1.24% (90 runs sampled)
fastest is set-value (by 206% avg)
# shallow (101 bytes)
deep-object x 9,416,410 ops/sec ±1.19% (89 runs sampled)
deep-property x 5,108,536 ops/sec ±0.98% (93 runs sampled)
deephas x 1,706,979 ops/sec ±0.98% (86 runs sampled)
dot-prop x 4,045,902 ops/sec ±1.10% (92 runs sampled)
dot2val x 5,862,418 ops/sec ±0.88% (91 runs sampled)
es5-dot-prop x 4,439,646 ops/sec ±1.18% (90 runs sampled)
lodash-set x 9,303,292 ops/sec ±1.19% (89 runs sampled)
object-path-set x 5,657,479 ops/sec ±0.95% (93 runs sampled)
object-set x 2,020,041 ops/sec ±0.92% (91 runs sampled)
set-value x 11,272,227 ops/sec ±1.36% (88 runs sampled)
fastest is set-value (by 213% avg)
Clone this library into a local directory:
1$ git clone https://github.com/jonschlinkert/set-value.git
Then install devDependencies and run benchmarks:
1$ npm install && node benchmark
These are just a few of the duplicate libraries on NPM.
this
being used improperly in the methods. I was able to patch it by binding the (plain) object to the methods, but it still fails 17 of 26 unit tests.Others that do the same thing, but use a completely different API
split
function to be passed on the options.If there are any regressions please create a bug report. Thanks!
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
Commits | Contributor |
---|---|
87 | jonschlinkert |
4 | doowb |
2 | mbelsky |
1 | dkebler |
1 | GlennKintscher |
1 | petermorlion |
1 | abetomo |
1 | zeidoo |
1 | ready-research |
1 | wtgtybhertgeghgtwtg |
Jon Schlinkert
Copyright © 2021, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on September 12, 2021.
9.8/10
Summary
Prototype Pollution in set-value
Affected Versions
= 3.0.0
Patched Versions
3.0.1
9.8/10
Summary
Prototype Pollution in set-value
Affected Versions
< 2.0.1
Patched Versions
2.0.1
7.3/10
Summary
Prototype Pollution in set-value
Affected Versions
>= 3.0.0, < 3.0.3
Patched Versions
3.0.3
7.3/10
Summary
Prototype Pollution in set-value
Affected Versions
>= 4.0.0, < 4.0.1
Patched Versions
4.0.1
7.3/10
Summary
Prototype Pollution in set-value
Affected Versions
< 2.0.1
Patched Versions
2.0.1
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 7/19 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More