object-path
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "object-path", | ||
"version": "0.3.0", | ||
"version": "0.5.1", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
18
index.js
@@ -70,2 +70,5 @@ (function (root, factory){ | ||
function set(obj, path, value, doNotReplace){ | ||
if (isNumber(path)) { | ||
path = [path]; | ||
} | ||
if (isEmpty(path)) { | ||
@@ -99,8 +102,13 @@ return obj; | ||
function del(obj, path) { | ||
if (isNumber(path)) { | ||
path = [path]; | ||
} | ||
if (isEmpty(obj)) { | ||
return void 0; | ||
} | ||
if (isEmpty(path)) { | ||
return obj; | ||
} | ||
if (isEmpty(obj)) { | ||
return undefined; | ||
} | ||
if(isString(path)) { | ||
@@ -195,2 +203,5 @@ return del(obj, path.split('.')); | ||
objectPath.get = function (obj, path, defaultValue){ | ||
if (isNumber(path)) { | ||
path = [path]; | ||
} | ||
if (isEmpty(path)) { | ||
@@ -205,2 +216,3 @@ return obj; | ||
} | ||
var currentPath = getKey(path[0]); | ||
@@ -207,0 +219,0 @@ |
{ | ||
"name": "object-path", | ||
"description": "Access deep properties using a path", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"author": { | ||
@@ -17,7 +17,7 @@ "name": "Mario Casciaro" | ||
"devDependencies": { | ||
"mocha": "~1.18.2", | ||
"mocha": "~1.20.1", | ||
"chai": "~1.9.1", | ||
"mocha-lcov-reporter": "~0.0.1", | ||
"coveralls": "~2.10.0", | ||
"istanbul": "~0.2.7" | ||
"coveralls": "~2.11.1", | ||
"istanbul": "~0.3.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
@@ -8,7 +8,7 @@ | ||
[![NPM](https://nodei.co/npm/object-path.png?downloads=true)](https://nodei.co/npm/object-path/) | ||
[![NPM version](https://badge.fury.io/js/object-path.png)](http://badge.fury.io/js/object-path) | ||
[![Build Status](https://travis-ci.org/mariocasciaro/object-path.png)](https://travis-ci.org/mariocasciaro/object-path) | ||
[![Coverage Status](https://coveralls.io/repos/mariocasciaro/object-path/badge.png)](https://coveralls.io/r/mariocasciaro/object-path) | ||
[![devDependency Status](https://david-dm.org/mariocasciaro/object-path/dev-status.svg)](https://david-dm.org/mariocasciaro/object-path#info=devDependencies) | ||
![Downloads](http://img.shields.io/npm/dm/object-path.svg) | ||
@@ -85,4 +85,4 @@ [![browser support](https://ci.testling.com/mariocasciaro/object-path.png)](https://ci.testling.com/mariocasciaro/object-path) | ||
[Mario Casciaro](https://github.com/mariocasciaro) - Author | ||
[Paulo Cesar](https://github.com/pocesar) - Major contributor | ||
* [Mario Casciaro](https://github.com/mariocasciaro) - Author | ||
* [Paulo Cesar](https://github.com/pocesar) - Major contributor | ||
@@ -89,0 +89,0 @@ |
31
test.js
@@ -24,2 +24,8 @@ var expect = require('chai').expect, | ||
it('should work with number path', function() { | ||
var obj = getTestObj(); | ||
expect(objectPath.get(obj.b.d, 0)).to.be.equal("a"); | ||
expect(objectPath.get(obj.b, 0)).to.be.equal(void 0); | ||
}); | ||
it('should return the value under deep object', function() { | ||
@@ -106,2 +112,8 @@ var obj = getTestObj(); | ||
it('should set value using number path', function() { | ||
var obj = getTestObj(); | ||
objectPath.set(obj.b.d, 0, "o"); | ||
expect(obj).to.have.deep.property("b.d.0", "o"); | ||
}); | ||
it('should set value under deep object', function() { | ||
@@ -183,2 +195,9 @@ var obj = getTestObj(); | ||
}); | ||
it('should push value to existing array using number path', function() { | ||
var obj = getTestObj(); | ||
objectPath.push(obj.b.e, 0, "l"); | ||
expect(obj).to.have.deep.property("b.e.0.0", "l"); | ||
}); | ||
}); | ||
@@ -261,4 +280,4 @@ | ||
var obj = {}; | ||
expect(objectPath.empty()).to.equal(undefined); | ||
expect(objectPath.empty(obj, 'path')).to.equal(undefined); | ||
expect(objectPath.empty()).to.equal(void 0); | ||
expect(objectPath.empty(obj, 'path')).to.equal(void 0); | ||
expect(objectPath.empty(obj, '')).to.equal(obj); | ||
@@ -330,5 +349,11 @@ | ||
it('should return undefined on empty object', function(){ | ||
expect(objectPath.del({}, 'a')).to.equal(undefined); | ||
expect(objectPath.del({}, 'a')).to.equal(void 0); | ||
}); | ||
it('should work with number path', function(){ | ||
var obj = getTestObj(); | ||
objectPath.del(obj.b.d, 1); | ||
expect(obj.b.d).to.deep.equal(['a']); | ||
}); | ||
it('should delete deep paths', function(){ | ||
@@ -335,0 +360,0 @@ var obj = getTestObj(); |
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
22415
540