Comparing version 0.2.2 to 0.2.3
@@ -143,1 +143,14 @@ /** | ||
export declare function mergeBy<T>(items: T[], idKey?: string): T[]; | ||
/** | ||
Convert an Array of objects with fixed keys to an object with variable keys. | ||
E.g.: | ||
toObject([ | ||
{key: 'firstname', value: 'Chris'}, | ||
{key: 'lastname', value: 'Brown'}, | ||
]) => [ | ||
{firstname: 'Chris', lastname: 'Brown'}, | ||
] | ||
*/ | ||
export declare function toObject<T>(items: T[], nameKey?: string, valueKey?: string): {}; |
22
index.js
@@ -266,1 +266,23 @@ /** | ||
exports.mergeBy = mergeBy; | ||
/** | ||
Convert an Array of objects with fixed keys to an object with variable keys. | ||
E.g.: | ||
toObject([ | ||
{key: 'firstname', value: 'Chris'}, | ||
{key: 'lastname', value: 'Brown'}, | ||
]) => [ | ||
{firstname: 'Chris', lastname: 'Brown'}, | ||
] | ||
*/ | ||
function toObject(items, nameKey, valueKey) { | ||
if (nameKey === void 0) { nameKey = 'key'; } | ||
if (valueKey === void 0) { valueKey = 'value'; } | ||
var object = {}; | ||
items.forEach(function (item) { | ||
object[item[nameKey]] = item[valueKey]; | ||
}); | ||
return object; | ||
} | ||
exports.toObject = toObject; |
{ | ||
"name": "tarry", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Utility library for manipulating JavaScript Arrays", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
13769
383