2.0.2 β€’ Published 1 year ago

@blakek/make-lookup v2.0.2

Weekly downloads
7
License
MIT
Repository
github
Last release
1 year ago

make-lookup

πŸ“’ Make a lookup object from an array of objects

Takes a list of items in an array an changes it to an object for fast access.

Install

Using Yarn:

$ yarn add @blakek/make-lookup

…or using npm:

$ npm i --save @blakek/make-lookup

Usage

import { makeLookup } from '@blakek/make-lookup';

const users = [
  { sites: { github: { username: 'blakek' } } },
  { sites: { github: { username: 'gsandf' } } },
  { sites: { github: { username: 'google' } } }
];

const usersByUsername = makeLookup(users, 'sites.github.username');

console.log(usersByUsername.blakek);
// => { sites: { github: { username: 'blakek' } } }

API

makeLookup

function makeLookup<T>(
  inputArray: any[],
  lookupProperty: Array<number | string> | string;
): Record<string, T>;

Creates a lookup object for a given array.

lookupProperty is a path to the property in either dot notation or an array of path parts. See blakek/deep for details on this path.

Contributing

Node.js and Yarn are required to work with this project.

To install all dependencies, run:

yarn

Useful Commands

yarn buildBuilds the project to ./dist
yarn formatFormat the source following the Prettier styles
yarn testRun project tests
yarn test --watchRun project tests, watching for file changes

License

MIT

2.0.2

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago