npm.io
1.9.8 • Published 4 years ago

@guanghechen/locate-helper

Licence
MIT
Version
1.9.8
Deps
0
Size
7 kB
Vulns
0
Weekly
0
Stars
4

@guanghechen/locate-helper


Utils for locate nearest filepath matched the given pattern.

Install

  • npm

    npm install --save @guanghechen/locate-helper
  • yarn

    yarn add @guanghechen/locate-helper

Usage

locateNearestFilepath
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
export function findNearestFilepath(
  currentDir: string,
  testFilepath: (filepath: string) => boolean,
): string | null

Find a nearest filepath from the give currentDirwhich matched the give tester testFilepath.

  • currentDir: The starting directory of the searching.

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

locateLatestPackageJson
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.

Keywords