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

object-path

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-path - npm Package Compare versions

Comparing version 0.11.1 to 0.11.2

26

index.js

@@ -17,5 +17,10 @@ (function (root, factory){

var
toStr = Object.prototype.toString,
_hasOwnProperty = Object.prototype.hasOwnProperty;
var toStr = Object.prototype.toString;
function hasOwnProperty(obj, prop) {
if(obj == null) {
return false
}
//to handle objects with null prototypes (too edge case?)
return Object.prototype.hasOwnProperty.call(obj, prop)
}

@@ -30,3 +35,3 @@ function isEmpty(value){

for (var i in value) {
if (_hasOwnProperty.call(value, i)) {
if (hasOwnProperty(value, i)) {
return false;

@@ -84,3 +89,3 @@ }

function getShallowProperty(obj, prop) {
if (options.includeInheritedProps || (typeof prop === 'number' && Array.isArray(obj)) || _hasOwnProperty.call(obj, prop)) {
if (options.includeInheritedProps || (typeof prop === 'number' && Array.isArray(obj)) || hasOwnProperty(obj, prop)) {
return obj[prop];

@@ -122,6 +127,2 @@ }

objectPath.has = function (obj, path) {
if (obj == null) {
return false;
}
if (typeof path === 'number') {

@@ -134,3 +135,3 @@ path = [path];

if (!path || path.length === 0) {
return false;
return !!obj;
}

@@ -140,4 +141,5 @@

var j = getKey(path[i]);
if((typeof j === 'number' && isArray(obj) && j < obj.length) ||
(options.includeInheritedProps ? (j in Object(obj)) : _hasOwnProperty.call(obj, j))) {
(options.includeInheritedProps ? (j in Object(obj)) : hasOwnProperty(obj, j))) {
obj = obj[j];

@@ -193,3 +195,3 @@ } else {

for (i in value) {
if (_hasOwnProperty.call(value, i)) {
if (hasOwnProperty(value, i)) {
delete value[i];

@@ -196,0 +198,0 @@ }

{
"name": "object-path",
"description": "Access deep object properties using a path",
"version": "0.11.1",
"version": "0.11.2",
"author": {

@@ -6,0 +6,0 @@ "name": "Mario Casciaro"

@@ -553,7 +553,12 @@ 'use strict';

it('should return false for empty path', function () {
it('should handle empty paths properly', function () {
var obj = getTestObj();
expect(objectPath.has(obj, '')).to.be.equal(false);
expect(objectPath.has(obj, [])).to.be.equal(false);
expect(objectPath.has(obj, [''])).to.be.equal(false);
obj[''] = 1
expect(objectPath.has(obj, '')).to.be.equal(true);
expect(objectPath.has(obj, [''])).to.be.equal(true);
expect(objectPath.has(obj, [])).to.be.equal(true);
expect(objectPath.has(null, [])).to.be.equal(false);
});

@@ -618,2 +623,13 @@

});
it('should work with deep undefined/null values', function() {
var obj = {};
expect(objectPath.has(obj, 'missing.test')).to.be.equal(false);
obj.missing = null;
expect(objectPath.has(obj, 'missing.test')).to.be.equal(false);
obj.sparseArray = [1, undefined, 3]
expect(objectPath.has(obj, 'sparseArray.1.test')).to.be.equal(false);
});
});

@@ -620,0 +636,0 @@

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