Comparing version 1.0.0 to 1.1.0
@@ -5,3 +5,18 @@ module.exports = function(rootLevel, keys, defaultValue) { | ||
var key = keys[i]; | ||
var val = level[key]; | ||
var val; | ||
if (key instanceof Array) { | ||
var keyOptions = key; | ||
var keyElm; | ||
for (var j = 0; j < keyOptions.length; j++) { | ||
keyElm = keyOptions[j]; | ||
val = level[keyElm]; | ||
if (val !== undefined && val !== null) { | ||
break; | ||
} | ||
} | ||
} else { | ||
val = level[key]; | ||
} | ||
if (val === undefined || val === null) { | ||
@@ -8,0 +23,0 @@ if (defaultValue !== undefined) { |
{ | ||
"name": "diver", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Deep access to nested object values", | ||
@@ -17,5 +17,14 @@ "main": "index.js", | ||
}, | ||
"dependencies": { | ||
"chai": "^2.2.0" | ||
} | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/grudzinski/diver.git" | ||
}, | ||
"keywords": [ | ||
"deep", | ||
"object" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/grudzinski/diver/issues" | ||
}, | ||
"homepage": "https://github.com/grudzinski/diver" | ||
} |
@@ -25,2 +25,15 @@ var chai = require('chai'); | ||
it('works with array of keys per level', function() { | ||
var result = get({ x: { y: 'y', z: 'z' } }, ['x', ['y','z']]); | ||
assert.strictEqual(result, 'y'); | ||
result = get({ x: { y: 'y', z: 'z' } }, ['x', ['other','z']]); | ||
assert.strictEqual(result, 'z'); | ||
result = get({ x: { y: 'y', z: 'z' } }, ['x', ['other','other2']], 'default'); | ||
assert.strictEqual(result, 'default'); | ||
}); | ||
}); |
@@ -13,4 +13,2 @@ var chai = require('chai'); | ||
debugger; | ||
set(testObject, ['x', 'y', 'z'], 'test'); | ||
@@ -22,2 +20,13 @@ | ||
it('works 2', function() { | ||
var testObject = {}; | ||
set(testObject, ['x', 'y', 'z'], 'test'); | ||
set(testObject, ['x', 'y', 'q'], 'test2'); | ||
assert.deepEqual(testObject, { x: { y: { z: 'test', q: 'test2' } } }); | ||
}); | ||
}); |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
2963
0
85
1
0
0
- Removedchai@^2.2.0
- Removedassertion-error@1.0.0(transitive)
- Removedchai@2.3.0(transitive)
- Removeddeep-eql@0.1.3(transitive)
- Removedtype-detect@0.1.1(transitive)