Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deep-property

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-property - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

test/remove.js

37

index.js

@@ -69,2 +69,39 @@

/*
* Removes a deeply nested property.
*
* If an intermediate property of the specified path doesn't exist,
* we bail early.
*
* Arguments:
*
* obj Object to remove property from.
*
* path [string] Dot-separated path specifier to nested
* property to remove. Array indexes are not supported.
* Example: "contact.name.first".
*
* Returns: [boolean] TRUE if property was removed, otherwise FALSE.
*/
module.exports.remove = function (obj, path) {
if (typeof obj === 'undefined' || typeof path === 'undefined') {
return false;
}
var tokens = parse(path);
for (var i = 0, len = tokens.length; i < len; i++) {
if (! obj || ! obj.hasOwnProperty(tokens[i])) {
return false;
}
if (i == (len - 1)) {
delete obj[tokens[i]];
return true;
} else {
obj = obj[tokens[i]];
}
}
return false
};
/*
* Detects whether a given object has a specified nested property.

@@ -71,0 +108,0 @@ *

2

package.json
{
"name": "deep-property",
"version": "1.0.0",
"version": "1.1.0",
"description": "Fetch, set, and test deeply nested object properties",

@@ -5,0 +5,0 @@ "main": "index.js",

# deep-property
Enables deep property manipulation and inspection without worring about
Enables deep property manipulation and inspection without worrying about
exceptions.

@@ -23,11 +23,13 @@

props.get(sample, 'name.first'); // John
props.get(sample, 'name.middle'); // C
props.get(sample, 'name.last'); // Reilly
props.get(sample, 'job.title'); // Actor
props.get(sample, 'name.first'); // John
props.get(sample, 'name.middle'); // C
props.get(sample, 'name.last'); // Reilly
props.get(sample, 'job.title'); // Actor
props.has(sample, 'name.first'); // True
props.has(sample, 'name.title'); // False
props.has(sample, 'job.title'); // True
props.has(sample, 'job.salary'); // False
props.remove(sample, 'name.middle'); // True
props.has(sample, 'name.first'); // True
props.has(sample, 'name.title'); // False
props.has(sample, 'job.title'); // True
props.has(sample, 'job.salary'); // False
```

@@ -40,3 +42,2 @@

first: 'John',
middle: 'C',
last: 'Reilly'

@@ -64,3 +65,4 @@ },

- `has`: `false`
- `remove`: `false`
- Paths with blank sections (`path.to..nothing` or `path.to.nothing.`)
will be considered invalid.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc