findUpward
findUpward<
T>(startDir,check,stop?):Promise<T|undefined>
Defined in: find-upward.ts:30
Walks upward from startDir — startDir itself first, then its parent,
then its parent’s parent, and so on — calling check at each directory
and returning the first result it produces that isn’t undefined.
stop, when given, is checked at a directory only after check has
already come back empty there (so that directory is still fully
checked before stopping) — return true to end the walk there without
a result, instead of continuing to its parent. Common use: stop at a
repo root (see hasGitEntry) rather than wandering into an
unrelated enclosing directory tree.
Always terminates: directory nesting is finite, and walking stops unconditionally once the filesystem root is reached (its own parent).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”startDir
Section titled “startDir”string
(dir) => T | Promise<T | undefined> | undefined
(dir) => boolean | Promise<boolean>
Returns
Section titled “Returns”Promise<T | undefined>
Example
Section titled “Example”import { findUpward, hasGitEntry } from "@theholocron/fs-utils";
const configDir = await findUpward( process.cwd(), async (dir) => ((await fileExists(join(dir, "app.config.json"))) ? dir : undefined), hasGitEntry);