Return the filename or parent directory path of a file or directory by walking
up parent directories. The package name is from emacs builtin lisp function
find-dominant-file
. This package supports TypeScript as well.
npm i find-dominant-file -s
/foo
└── bar
└── baz
├── qux
└── quxx
└── quxxx
├── quxxxx
└── quxxxxx
const myFile = findDominantFile('/foo/bar/baz/quxx/quxxx', 'quxx');
//=> '/foo/bar/baz/quxx'
const myDir = findDominantFile('/foo/bar/baz/quxx/quxxx', 'quxx', true);
//=> '/foo/bar/baz'
Returns the path of file or undefined.
Returns the path of the directory which contains the file or undefined.
Returns the path of the first found file in the list or undefined.
Returns the path of the directory which contains the first found file in the list or undefined.
MIT © Zhang Kai Yu