From 92ef4682207cf115a87b2509a68545ceeb87e71c Mon Sep 17 00:00:00 2001 From: "Johannes J. Schmidt" Date: Mon, 2 Jun 2014 15:52:19 +0200 Subject: [PATCH] allow removing of components in merge via undefined or null --- index.js | 4 ++-- package.json | 2 +- test/merge_test.js | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7ca8d9f..7d8d451 100644 --- a/index.js +++ b/index.js @@ -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]; } }); diff --git a/package.json b/package.json index 4c835c6..8613c6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docuri", - "version": "3.0.1", + "version": "3.0.2", "description": "Rich document ids for CouchDB", "main": "index.js", "scripts": { diff --git a/test/merge_test.js b/test/merge_test.js index 4386968..684ba0f 100644 --- a/test/merge_test.js +++ b/test/merge_test.js @@ -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(); +}); + +