# components-lookup

> Look for components and gather information about them

Latest version **7.0.1** (published 2021-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install components-lookup
pnpm add components-lookup
yarn add components-lookup
bun add components-lookup
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.0.1 |
| Published | 2021-01-17 |
| First published | 2017-05-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | electerious |
| Keywords | components, component, lookup, files, data, view, template |

## Links

- npm: https://www.npmjs.com/package/components-lookup
- Repository: https://github.com/comwrap/components-lookup
- Issues: https://github.com/comwrap/components-lookup/issues
- npm.io page: https://npm.io/package/components-lookup

## Dependencies (5)

- [glob](https://npm.io/package/glob.md) ^7.1.3
- [p-map](https://npm.io/package/p-map.md) ^4.0.0
- [locate-path](https://npm.io/package/locate-path.md) ^6.0.0
- [is-plain-obj](https://npm.io/package/is-plain-obj.md) ^3.0.0
- [rename-extension](https://npm.io/package/rename-extension.md) ^4.0.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 7.0.1 (latest) — 2021-01-17
- 4.0.0-0 (beta) — 2017-07-28
- 7.0.0 — 2020-03-20
- 6.0.0 — 2018-11-01
- 5.0.0 — 2018-06-07
- 4.0.2 — 2017-08-08
- 4.0.1 — 2017-08-01
- 4.0.0 — 2017-07-31
- 3.1.1 — 2017-06-12
- 3.1.0 — 2017-06-11
- 3.0.0 — 2017-06-11
- 2.1.0 — 2017-06-11
- 2.0.0 — 2017-06-11
- 1.0.3 — 2017-06-10
- 1.0.2 — 2017-06-07
- … 2 more at https://npm.io/package/components-lookup/versions

## README

# components-lookup

![Build](https://github.com/Malvid/components-lookup/workflows/Build/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/Malvid/components-lookup/badge.svg?branch=master)](https://coveralls.io/github/Malvid/components-lookup?branch=master)

Look for components and gather information about them.

## Install

```
npm install components-lookup
```

## Usage

### Structure

```
.
├── index.config.json
├── index.data.json
└── index.njk
```

### Code

```js
const componentsLookup = require('components-lookup')

const resolvers = [
	{
		id: 'view',
		resolve: (fileName, fileExt) => [ `${ fileName }${ fileExt }` ]
	},
	{
		id: 'data',
		resolve: (fileName, fileExt) => [ `${ fileName }.data.json`, `${ fileName }.data.js` ]
	},
	{
		id: 'notes',
		resolve: (fileName, fileExt) => [ `${ fileName }.md` ]
	},
	{
		id: 'config',
		parse: async (contents, filePath) => JSON.parse(await contents),
		resolve: (fileName, fileExt) => [ `${ fileName }.config.json` ]
	}
]

componentsLookup('**/*.njk', resolvers).then(console.log)
```

### Output

```js
[
	{
		index: 0,
		id: '8bf47e30644eb32653aa6284ebe2fb9c17e3587d',
		name: 'index',
		src: 'index.njk',
		url: '/index.html',
		data: [
			{ index: 0, id: 'view', data: 'Hello World!' },
			{ index: 1, id: 'data', data: '{}' },
			{ index: 2, id: 'notes', data: null },
			{ index: 3, id: 'config', data: {} }
		]
	}
]
```

## Parameters

- `pattern` `{String}` - Files to look for using a glob pattern.
- `resolvers` `{Array}`
	- `resolver` `{Object}` - Object that helps `components-lookup` to find files related to a component.
		- `id` `{String}` - Unique identifier for the file.
		- `parse` `{?Promise<String|Object>}` - Optional function that returns a promise resolving the content of a matching file. Can be used to modify the original content.
		- `resolve` `{Function}` - Function that returns an array of file names related to a component. Accepts the file name and extension of the current component.
- `opts` `{?Object}` - Options.
	- `cwd` `{?String}` - Directory in which to look for components. Defaults to `process.cwd()`.
	- `url` `{?Function}` - Function that accepts and returns a URL. Allows you to modify the URL of components. Defaults to `(url) => url`.

## Returns

- `{Promise<Array>}` - Components and their information.

---
_Source: https://npm.io/package/components-lookup · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
