Comparing version 2.3.0 to 2.4.0
18
index.js
@@ -63,2 +63,20 @@ 'use strict'; | ||
module.exports.has = function (obj, path) { | ||
if (!isObj(obj) || typeof path !== 'string') { | ||
return false; | ||
} | ||
var pathArr = getPathSegments(path); | ||
for (var i = 0; i < pathArr.length; i++) { | ||
obj = obj[pathArr[i]]; | ||
if (obj === undefined) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
function getPathSegments(path) { | ||
@@ -65,0 +83,0 @@ var pathArr = path.split('.'); |
{ | ||
"name": "dot-prop", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Get, set, or delete a property from a nested object using a dot path", | ||
@@ -16,3 +16,4 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "ava && xo" | ||
"test": "ava && xo", | ||
"bench": "matcha bench.js" | ||
}, | ||
@@ -42,4 +43,5 @@ "files": [ | ||
"ava": "*", | ||
"matcha": "^0.6.1", | ||
"xo": "*" | ||
} | ||
} |
@@ -40,3 +40,3 @@ # dot-prop [![Build Status](https://travis-ci.org/sindresorhus/dot-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/dot-prop) | ||
const obj = {foo: {bar: 'a'}}; | ||
dotProp.del(obj, 'foo.bar'); | ||
dotProp.delete(obj, 'foo.bar'); | ||
console.log(obj); | ||
@@ -46,3 +46,3 @@ //=> {foo: {}} | ||
obj.foo.bar = {x: 'y', y: 'x'}; | ||
dotProp.del(obj, 'foo.bar.x'); | ||
dotProp.delete(obj, 'foo.bar.x'); | ||
console.log(obj); | ||
@@ -49,0 +49,0 @@ //=> {foo: {bar: {y: 'x'}}} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4807
71
3