allow 0 as path element (closes #2)

pull/3/head
Karsten Gebbert 10 years ago
parent eb4f8732b5
commit c584f201fe

@ -30,31 +30,31 @@ exports.stringify = function(obj) {
obj = obj || {}; obj = obj || {};
var parts = []; var parts = [];
if (obj.type) { if (typeof obj.type !== 'undefined') {
parts.push(obj.type); parts.push(obj.type);
} else { } else {
if (obj.id || obj.subtype || obj.version || obj.index) parts.push(''); if (obj.id || obj.subtype || obj.version || obj.index) parts.push('');
} }
if (obj.id) { if (typeof obj.id !== 'undefined') {
parts.push(obj.id); parts.push(obj.id);
} else { } else {
if (obj.subtype || obj.version || obj.index) parts.push(''); if (obj.subtype || obj.version || obj.index) parts.push('');
} }
if (obj.subtype) { if (typeof obj.subtype !== 'undefined') {
parts.push(obj.subtype); parts.push(obj.subtype);
} else { } else {
if (obj.version || obj.index) parts.push(''); if (obj.version || obj.index) parts.push('');
} }
if (obj.version) { if (typeof obj.version !== 'undefined') {
parts.push(obj.version); parts.push(obj.version);
} else { } else {
if (obj.index) parts.push(''); if (obj.index) parts.push('');
} }
if (obj.index) parts.push(obj.index); if (typeof obj.index !== 'undefined') parts.push(obj.index);
return parts.join('/'); return parts.join('/');
}; };

@ -127,3 +127,14 @@ test('type/id/subtype/version/index', function(t) {
}), 'mytype/myid/mysubtype/myversion/myindex', 'should return string with type, id, subtype, version and index'); }), 'mytype/myid/mysubtype/myversion/myindex', 'should return string with type, id, subtype, version and index');
t.end(); t.end();
}); });
test('0/1/2/3/4', function(t) {
t.deepEqual(stringify({
type: 0,
id: 1,
subtype: 2,
version: 3,
index: 4
}), '0/1/2/3/4', 'should correctly handle number path fields');
t.end();
});

Loading…
Cancel
Save