@blakek/make-lookup
TypeScript icon, indicating that this package has built-in type declarations

2.0.2ย โ€ขย Publicย โ€ขย Published

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 build Builds the project to ./dist
yarn format Format the source following the Prettier styles
yarn test Run project tests
yarn test --watch Run project tests, watching for file changes

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @blakek/make-lookup

Weekly Downloads

10

Version

2.0.2

License

MIT

Unpacked Size

123 kB

Total Files

10

Last publish

Collaborators

  • blakek