Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/blakek/make-lookup

πŸ“’ Make a lookup object from an array of objects
https://github.com/blakek/make-lookup

functional-programming hash-lookup javascript lookup lookup-table map typescript

Last synced: 15 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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]:

```bash
$ yarn add @blakek/make-lookup
```

…or using [npm]:

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

## Usage

```js
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`

```ts
function makeLookup(
inputArray: any[],
lookupProperty: Array | string;
): Record;
```

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:

```bash
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

[blakek/deep]: https://github.com/blakek/deep
[node.js]: https://nodejs.org/
[npm]: https://npmjs.com/
[yarn]: https://yarnpkg.com/en/docs/