Comparing version 0.0.9 to 0.0.10
@@ -5,3 +5,3 @@ { | ||
"description": "Work with objects of different cased keys", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"keywords": [], | ||
@@ -8,0 +8,0 @@ "dependencies": { |
0.0.10 / 2014-08-30 | ||
=================== | ||
* Merge pull request #6 from segmentio/fix/shared-prefix | ||
* adding more tests for an edge case we didnt consider | ||
0.0.9 / 2014-08-30 | ||
@@ -3,0 +9,0 @@ ================== |
37
index.js
@@ -68,23 +68,26 @@ | ||
if (0 === path.indexOf(normalizedKey)) { | ||
path = path.substr(normalizedKey.length + 1); | ||
var child = obj[key]; | ||
var temp = path.substr(normalizedKey.length); | ||
if (temp.charAt(0) === '.' || temp.length === 0) { | ||
path = temp.substr(1); | ||
var child = obj[key]; | ||
// we're at the end and there is nothing. | ||
if (null == child) { | ||
finished = true; | ||
obj = null; | ||
return; | ||
} | ||
// we're at the end and there is nothing. | ||
if (null == child) { | ||
finished = true; | ||
obj = null; | ||
return; | ||
} | ||
// we're at the end and there is something. | ||
if (!path.length) { | ||
finished = true; | ||
// we're at the end and there is something. | ||
if (!path.length) { | ||
finished = true; | ||
return; | ||
} | ||
// step into child | ||
obj = child; | ||
// but we're done here | ||
return; | ||
} | ||
// step into child | ||
obj = child; | ||
// but we're done here | ||
return; | ||
} | ||
@@ -91,0 +94,0 @@ } |
{ | ||
"name": "obj-case", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Work with objects of different cased keys", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -43,2 +43,29 @@ | ||
it('should work with properties with same prefix', function () { | ||
var obj3 = { | ||
website: { | ||
left: 'aaaa' | ||
}, | ||
websites: { | ||
right: 'bbbb' | ||
} | ||
}; | ||
expect(objCase(obj3, 'website.left')).to.eql('aaaa'); | ||
expect(objCase(obj3, 'websites.right')).to.eql('bbbb'); | ||
var obj1 = { | ||
website: 'aaaa', | ||
websites: 'bbbb' | ||
}; | ||
expect(objCase(obj1, 'website')).to.eql('aaaa'); | ||
expect(objCase(obj1, 'websites')).to.eql('bbbb'); | ||
var obj2 = { | ||
websites: 'bbbb', | ||
website: 'aaaa' | ||
}; | ||
expect(objCase(obj2, 'website')).to.eql('aaaa'); | ||
expect(objCase(obj2, 'websites')).to.eql('bbbb'); | ||
}); | ||
describe('casing', function(){ | ||
@@ -45,0 +72,0 @@ it('should find crazy looking paths', function () { |
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
11911
259