find-dominant-file

Return the filename or parent directory path of a file or directory by walking up parent directories.

Usage no npm install needed!

<script type="module">
  import findDominantFile from 'https://cdn.skypack.dev/find-dominant-file';
</script>

README

find-dominant-file

NPM version Build Status Test Coverage Dependency Status DevDependency Status License PR Welcome

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.

Installation

npm i find-dominant-file -s

Usage

/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'

API

findDominantFile(dir, filename)

Returns the path of file or undefined.

findDominantFile(dir, filename, true)

Returns the path of the directory which contains the file or undefined.

findDominantFile(dir, [filename, ...])

Returns the path of the first found file in the list or undefined.

findDominantFile(dir, [filename, ...], true)

Returns the path of the directory which contains the first found file in the list or undefined.

License

MIT © Zhang Kai Yu