@guanghechen/locate-helper
v1.9.8
Published
Utils for locate nearest filepath matched the given pattern
Downloads
143
Readme
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 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
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.