allow removing of components in merge via undefined or null

pull/9/head
Johannes J. Schmidt 10 years ago
parent d0b80ee391
commit 92ef468220

@ -31,7 +31,7 @@ docuri.parts = function(obj) {
return obj[part];
});
while (parts.length && typeof parts[parts.length - 1] === 'undefined') {
while (parts.length && (typeof parts[parts.length - 1] === 'undefined' || parts[parts.length - 1] === null)) {
parts.pop();
}
@ -64,7 +64,7 @@ docuri.merge = function(obj, objToMerge) {
}
DEFINITION.forEach(function(part) {
if (objToMerge[part]) {
if (part in objToMerge) {
obj[part] = objToMerge[part];
}
});

@ -1,6 +1,6 @@
{
"name": "docuri",
"version": "3.0.1",
"version": "3.0.2",
"description": "Rich document ids for CouchDB",
"main": "index.js",
"scripts": {

@ -49,3 +49,14 @@ test('changing type component using object', function(t) {
t.end();
});
test('removing component with undefined', function(t) {
t.equal(merge('type/id/subtype/index/version', {version:undefined}), 'type/id/subtype/index', 'should return docuri string with version removed');
t.end();
});
test('removing component with null', function(t) {
t.equal(merge('type/id/subtype/index/version', {version:null}), 'type/id/subtype/index', 'should return docuri string with version removed');
t.end();
});

Loading…
Cancel
Save