# look-it-up

> Find a file or directory by walking up parent directories recursively. Zero dependency.

Latest version **2.1.0** (published 2021-12-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install look-it-up
pnpm add look-it-up
yarn add look-it-up
bun add look-it-up
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2021-12-05 |
| First published | 2020-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | exuanbo |
| Maintainers | exuanbo |
| Keywords | look-up, find-up, path, file, directory, search, match, recursive |

## Links

- npm: https://www.npmjs.com/package/look-it-up
- Repository: https://github.com/exuanbo/look-it-up
- Homepage: https://github.com/exuanbo/look-it-up#readme
- Issues: https://github.com/exuanbo/look-it-up/issues
- npm.io page: https://npm.io/package/look-it-up

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2021-12-05
- 2.0.0 — 2021-02-21
- 1.2.0 — 2021-02-15
- 1.1.2 — 2020-11-11
- 1.1.1 — 2020-11-09
- 1.1.0 — 2020-11-08
- 1.0.0 — 2020-11-08

## README

# look-it-up

> Find a file or directory by walking up parent directories recursively. Zero dependency.

[![npm](https://img.shields.io/npm/v/look-it-up.svg)](https://www.npmjs.com/package/look-it-up)
[![github workflow](https://img.shields.io/github/workflow/status/exuanbo/look-it-up/Node.js%20CI/main.svg)](https://github.com/exuanbo/look-it-up/actions/workflows/nodejs.yml)
[![Codecov branch](https://img.shields.io/codecov/c/gh/exuanbo/look-it-up/main.svg?token=speJkwSMKd)](https://codecov.io/gh/exuanbo/look-it-up)
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)

## Install

```sh
npm install look-it-up
```

### Usage

```js
import { existsSync } from 'fs'
import { join } from 'path'
import { lookItUp, lookItUpSync, exists } from 'look-it-up'

const contains = async (file, dir) => (await exists(join(dir, file))) ? dir : null
const containsSync = (file, dir) => existsSync(join(dir, file) ? dir : null

;(async () => {
  await lookItUp('.zshrc') //=> '~/.zshrc'

  await lookItUp(dir => containsSync('.zshrc', dir)) //=> '~'

  await lookItUp(async dir => await contains('.zshrc', dir)) //=> '~'
})()

lookItUpSync('.zshrc') //=> '~/.zshrc'

lookItUpSync(dir => containsSync('.zshrc', dir)) //=> '~'
```

## API

```ts
declare type MatcherResult = string | null | symbol
declare type Matcher = string | ((dir: string) => MatcherResult | Promise<MatcherResult>)
declare type MatcherSync = string | ((dir: string) => MatcherResult)

declare const lookItUp: (matcher: Matcher, dir?: string) => Promise<string | null>

declare const lookItUpSync: (matcher: MatcherSync, dir?: string) => string | null | never

declare const exists: (path: string) => Promise<boolean>
declare const stop: unique symbol

export { exists, lookItUp, lookItUpSync, stop }
```

## License

[MIT License](https://github.com/exuanbo/look-it-up/blob/main/LICENSE) © 2021 [Exuanbo](https://github.com/exuanbo)

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