dictify
v1.1.0
Published
An object-list to dictionary by specified key as an index
Downloads
2
Readme
dictify
Convert an object-list to dictionary by specified key as an index
Installation
npm install --save dictify
Example
var assert = require('assert');
var dictify = require('dictify');
var objectList = [
{ x: 'foo' },
{ x: 'bar' },
{ x: 'baz' },
];
var dict = dictify(objectList, 'x');
assert.deepEqual(
dict,
{
foo: { x: 'foo' },
bar: { x: 'bar' },
baz: { x: 'baz' },
}
);
var dictByFunctionIndexer = dictify(objectList, function(obj) {
return obj.x.toUpperCase();
});
assert.deepEqual(
dictByFunctionIndexer,
{
FOO: { x: 'foo' },
BAR: { x: 'bar' },
BAZ: { x: 'baz' },
}
);