开发者社区> 镜像站> NPM> @blakek/make-lookup
@blakek/make-lookup
📒 Make a lookup object from an array of objects
Last updated 5 months ago by blakek .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @blakek/make-lookup 
SYNC missed versions from official npm registry.

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

Current Tags

  • 2.0.2                                ...           latest (5 months ago)

3 Versions

  • 2.0.2                                ...           5 months ago
  • 2.0.0                                ...           6 months ago
  • 1.0.0                                ...           6 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 3
Last Month 6
Dependencies (1)
Dependents (0)
None