Merge pull request #3 from krgn/master

allow 0 as path element (closes #2)
pull/5/head
Johannes Jörg Schmidt 11 years ago
commit 25b45d4e2e

@ -30,31 +30,31 @@ exports.stringify = function(obj) {
obj = obj || {};
var parts = [];
if (obj.type) {
if (typeof obj.type !== 'undefined') {
parts.push(obj.type);
} else {
if (obj.id || obj.subtype || obj.version || obj.index) parts.push('');
}
if (obj.id) {
if (typeof obj.id !== 'undefined') {
parts.push(obj.id);
} else {
if (obj.subtype || obj.version || obj.index) parts.push('');
}
if (obj.subtype) {
if (typeof obj.subtype !== 'undefined') {
parts.push(obj.subtype);
} else {
if (obj.version || obj.index) parts.push('');
}
if (obj.version) {
if (typeof obj.version !== 'undefined') {
parts.push(obj.version);
} else {
if (obj.index) parts.push('');
}
if (obj.index) parts.push(obj.index);
if (typeof obj.index !== 'undefined') parts.push(obj.index);
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');
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