Delete nested properties from an object using dot notation.
Installations
npm install unset-value
Developer
jonschlinkert
Developer Guide
Module System
CommonJS
Min. Node Version
>=10
Typescript Support
Yes
Node Version
14.17.5
NPM Version
6.14.14
Statistics
34 Stars
24 Commits
12 Forks
4 Watching
1 Branches
7 Contributors
Updated on 23 Jul 2024
Bundle Size
4.75 kB
Minified
1.64 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
4,342,601,593
Last day
-9.6%
2,626,555
Compared to previous day
Last week
2.8%
16,520,833
Compared to previous week
Last month
33.6%
61,487,212
Compared to previous month
Last year
-21.3%
624,115,888
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
3
unset-value
Delete nested properties from 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
Install with npm:
1$ npm install --save unset-value
Usage
1var unset = require('unset-value'); 2unset(obj, prop);
Params
obj
{object}: The object to unsetprop
onprop
{string | string[]}: The property to unset. Dot-notation may be used or an array of nested properties.
Examples
Updates the object when a property is deleted
1var obj = {a: 'b'}; 2unset(obj, 'a'); 3console.log(obj); 4//=> {}
Returns true when a property is deleted
1unset({a: 'b'}, 'a') // true
Returns true
when a property does not exist
This is consistent with delete
behavior in that it does not
throw when a property does not exist.
1unset({a: {b: {c: 'd'}}}, 'd') // true
delete nested values
1var one = {a: {b: {c: 'd'}}}; 2unset(one, 'a.b'); 3console.log(one); 4//=> {a: {}} 5 6var two = {a: {b: {c: 'd'}}}; 7unset(two, ['a', 'b', 'c']); 8console.log(two); 9//=> {a: {b: {}}} 10 11var three = {a: {b: {c: 'd', e: 'f'}}}; 12unset(three, 'a.b.c'); 13console.log(three); 14//=> {a: {b: {e: 'f'}}}
throws on invalid args
1unset(); 2// 'expected an object.'
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
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
Building docs
(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
Related projects
You might also be interested in these projects:
- get-value: Use property paths like 'a.b.c' to get a nested value from an object. Even works… more | homepage
- get-values: Return an array of all values from the given object. | homepage
- omit-value: Omit properties from an object or deeply nested property of an object using object path… more | homepage
- put-value: Update only existing values from an object, works with dot notation paths like
a.b.c
and… more | homepage - set-value: Create nested values and any intermediaries using dot notation (
'a.b.c'
) paths. | homepage - union-value: Set an array of unique values as the property of an object. Supports setting deeply… more | homepage
- upsert-value: Update or set nested values and any intermediaries with dot notation (
'a.b.c'
) paths. | homepage
Contributors
Commits | Contributor |
---|---|
11 | jonschlinkert |
4 | danez |
2 | wtgtybhertgeghgtwtg |
1 | TrySound |
1 | bluelovers |
Author
Jon Schlinkert
License
Copyright © 2021, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on March 18, 2021.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 4/21 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-11-25
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