Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
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.
Install with npm
$ npm i unset-value --save
var unset = require('unset-value');
var obj = {a: {b: {c: 'd', e: 'f'}}};
unset(obj, 'a.b.c');
console.log(obj);
//=> {a: {b: {e: 'f'}}};
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.'
a.b.c
) to get a nested value from an object. | homepage a.b.c
and… more | homepage'a.b.c'
) paths. | 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-cli on October 30, 2015.
FAQs
Delete nested properties from an object using dot notation.
The npm package unset-value receives a total of 9,960,255 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.