the-lodash
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

Lodash Extender

Build Status

Library meant to extend capabilites of NodeJS Lodash library.

_.makeDict

Create a dictionary object from array.

Signature:

_.makeDict(array, cbKey, cbValue) : returns dict.

array: array of items

cbKey: function to return key of each item.

cbValue: optional callback to set value for each item. if not set the value would be the item itself.

Usage 1:

var items = ['cat', 'dog', 'elephant']
var dict = _.makeDict(items, x => x, x => x.length);
console.log(dict);

Outputs:

{
    "cat": 3,
    "dog": 3,
    "elephant": 8,
}

Usage 2:

var items = [
    { id: 1, name: 'cat' }, 
    { id: 3, name: 'dog' }, 
    { id: 4, name: 'elephant' }
]
var dict = _.makeDict(items, x => x.id, x => ({ name: x.name }));
console.log(dict);

Outputs:

{
    1: {
        "name": "cat"
    },
    3: {
        "name": "dog"
    },
    4: {
        "name", "elephant"
    }
}

Publishing

$ ./publish.sh

Updating NPM Key

$ travis encrypt <NPM-KEY-GOES-HERE> --add deploy.api_key

Readme

Keywords

none

Package Sidebar

Install

npm i the-lodash

Weekly Downloads

79

Version

2.1.2

License

MIT

Unpacked Size

69.8 kB

Total Files

63

Last publish

Collaborators

  • rubenhak