# @guanghechen/locate-helper

> Utils for locate nearest filepath matched the given pattern

Latest version **1.9.8** (published 2022-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @guanghechen/locate-helper
pnpm add @guanghechen/locate-helper
yarn add @guanghechen/locate-helper
bun add @guanghechen/locate-helper
```

## Health

**Score 35/100 (D)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.9.8 |
| Published | 2022-07-27 |
| First published | 2021-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 14.15.0 |
| Dependencies | 0 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | guanghechen |
| Maintainers | lemonclown |
| Keywords | util, node.js, locate |

## Links

- npm: https://www.npmjs.com/package/@guanghechen/locate-helper
- Repository: https://github.com/guanghechen/node-scaffolds
- Homepage: https://github.com/guanghechen/node-scaffolds/tree/main/packages/locate-helper#readme
- Issues: https://github.com/guanghechen/node-scaffolds/issues
- npm.io page: https://npm.io/package/@guanghechen/locate-helper

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.9.8 (latest) — 2022-07-27
- 1.9.7 — 2022-07-17
- 1.9.6 — 2022-07-10
- 1.9.5 — 2022-06-03
- 1.9.4 — 2022-04-27
- 1.9.3 — 2022-04-10
- 1.9.2 — 2022-03-12
- 1.9.1 — 2022-02-23
- 1.9.0 — 2022-02-17
- 1.9.0-alpha.0 — 2022-02-16
- 1.8.6 — 2022-01-15
- 1.8.5 — 2021-12-05
- 1.8.4 — 2021-10-28
- 1.8.3 — 2021-08-18
- 1.8.2 — 2021-08-14
- … 37 more at https://npm.io/package/@guanghechen/locate-helper/versions

## README

<header>
  <h1 align="center">
    <a href="https://github.com/guanghechen/node-scaffolds/tree/main/packages/locate-helper#readme">@guanghechen/locate-helper</a>
  </h1>
  <div align="center">
    <a href="https://www.npmjs.com/package/@guanghechen/locate-helper">
      <img
        alt="Npm Version"
        src="https://img.shields.io/npm/v/@guanghechen/locate-helper.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@guanghechen/locate-helper">
      <img
        alt="Npm Download"
        src="https://img.shields.io/npm/dm/@guanghechen/locate-helper.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@guanghechen/locate-helper">
      <img
        alt="Npm License"
        src="https://img.shields.io/npm/l/@guanghechen/locate-helper.svg"
      />
    </a>
    <a href="https://github.com/nodejs/node">
      <img
        alt="Node.js Version"
        src="https://img.shields.io/node/v/@guanghechen/locate-helper"
      />
    </a>
    <a href="https://github.com/facebook/jest">
      <img
        alt="Tested with Jest"
        src="https://img.shields.io/badge/tested_with-jest-9c465e.svg"
      />
    </a>
    <a href="https://github.com/prettier/prettier">
      <img
        alt="Code Style: prettier"
        src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square"
      />
    </a>
  </div>
</header>
<br/>


Utils for locate nearest filepath matched the given pattern.

## Install

* npm

  ```bash
  npm install --save @guanghechen/locate-helper
  ```

* yarn

  ```bash
  yarn add @guanghechen/locate-helper
  ```

## Usage

### `locateNearestFilepath`

```typescript
export function locateNearestFilepath(
  currentDir: string,
  filenames: string[],
): string | null
```

Locate a nearest filepath from the given `currentDir` which name included
in the give `filenames`.

  * `currentDir`: The starting directory of the locating.

  * `filenames`: The file name list of the file to be searched, the first existed filepath in the list will be returned as the result.

### `findNearestFilepath`

```typescript
export function findNearestFilepath(
  currentDir: string,
  testFilepath: (filepath: string) => boolean,
): string | null
```

Find a nearest filepath from the give `currentDir`which matched the give
tester `testFilepath`.

  * `currentDir`: The starting directory of the searching.

  * `testFilepath`: Test if a given filepath is an expected one.

### `locateLatestPackageJson`

```typescript
export function locateLatestPackageJson(currentDir: string): string | null
```

Find the latest `package.json` under the give `currentDir` or its ancestor path.

  * `currentDir`: The starting directory of the locating.

[homepage]: https://github.com/guanghechen/node-scaffolds/tree/main/packages/locate-helper#readme

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