append-to-all-attributes
Advanced tools
Comparing version 1.0.2 to 1.0.3
16
index.js
module.exports = (object, stringToAppend) => { | ||
const new_object = {}; | ||
for (const [key, value] of Object.entries(object)) { | ||
new_object[`${key}${stringToAppend}`] = value; | ||
if (Array.isArray(object)) { | ||
const new_array = []; | ||
object.forEach((item, index) => { | ||
new_array[index] = module.exports(item, stringToAppend); | ||
}); | ||
return new_array; | ||
} else { | ||
const new_object = {}; | ||
for (const [key, value] of Object.entries(object)) { | ||
new_object[`${key}${stringToAppend}`] = value; | ||
} | ||
return new_object; | ||
} | ||
return new_object; | ||
}; |
{ | ||
"name": "append-to-all-attributes", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Append a string to all attributes in the object passed", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
36
test.js
@@ -25,1 +25,37 @@ import test from 'ava'; | ||
}); | ||
test('append _triplet to array', t => { | ||
t.deepEqual( | ||
appendToAllAttributes( | ||
[ | ||
{ | ||
cms: { | ||
status: 'GOOD', | ||
comment: '', | ||
cause: '' | ||
}, | ||
csc: { | ||
status: 'BAD', | ||
comment: '', | ||
cause: '' | ||
} | ||
} | ||
], | ||
'_triplet' | ||
), | ||
[ | ||
{ | ||
cms_triplet: { | ||
status: 'GOOD', | ||
comment: '', | ||
cause: '' | ||
}, | ||
csc_triplet: { | ||
status: 'BAD', | ||
comment: '', | ||
cause: '' | ||
} | ||
} | ||
] | ||
); | ||
}); |
2891
73