Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
unset-value
Advanced tools
Package description
The unset-value npm package is used to remove properties from an object. It allows you to delete a nested property from an object using a dot-path or an array of keys without mutating the original object.
Unsetting a property using a dot-path
This feature allows you to remove a nested property from an object by specifying the path to the property using a string with dot notation. For example, if you have an object `{ a: { b: { c: 7 } } }` and you want to remove the property `c`, you can use `unset(object, 'a.b.c')`.
{"object": {"a": {"b": {"c": 7}}}, "path": "a.b.c"}
Unsetting a property using an array of keys
This feature is similar to the dot-path method but uses an array of keys to specify the path to the property. It is useful when property names are dynamic or not valid identifiers. For example, `unset(object, ['a', 'b', 'c'])` will remove the property `c` from the object.
{"object": {"a": {"b": {"c": 7}}}, "path": ["a", "b", "c"]}
Lodash's unset function is a part of the larger Lodash utility library. It offers similar functionality to unset-value, allowing you to remove nested properties from objects. Lodash is a well-established library with a wide range of utility functions, but it is larger in size compared to the focused unset-value package.
Dot-prop is a package that allows you to get, set, or delete properties from a nested object using a dot path. While it provides similar functionality for deleting properties, it also includes methods for getting and setting values, making it more versatile but also broader in scope than unset-value.
Readme
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 with npm:
$ npm install --save unset-value
var unset = require('unset-value');
unset(obj, prop);
obj
{object}: The object to unset prop
onprop
{string | string[]}: The property to unset. Dot-notation may be used or an array of nested properties.var obj = {a: 'b'};
unset(obj, 'a');
console.log(obj);
//=> {}
unset({a: 'b'}, 'a') // true
true
when a property does not existThis is consistent with delete
behavior in that it does not
throw when a property does not exist.
unset({a: {b: {c: 'd'}}}, 'd') // true
var one = {a: {b: {c: 'd'}}};
unset(one, 'a.b');
console.log(one);
//=> {a: {}}
var two = {a: {b: {c: 'd'}}};
unset(two, ['a', 'b', 'c']);
console.log(two);
//=> {a: {b: {}}}
var three = {a: {b: {c: 'd', e: 'f'}}};
unset(three, 'a.b.c');
console.log(three);
//=> {a: {b: {e: 'f'}}}
unset();
// 'expected an object.'
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:
$ 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:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
a.b.c
and… more | homepage'a.b.c'
) paths. | homepage'a.b.c'
) paths. | homepageCommits | Contributor |
---|---|
11 | jonschlinkert |
4 | danez |
2 | wtgtybhertgeghgtwtg |
1 | TrySound |
1 | bluelovers |
Jon Schlinkert
Copyright © 2021, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on March 18, 2021.
FAQs
Delete nested properties from an object using dot notation.
The npm package unset-value receives a total of 11,861,488 weekly downloads. As such, unset-value popularity was classified as popular.
We found that unset-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
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.