2.2.0 • Published 5 years ago

find-dominant-file v2.2.0

Weekly downloads
317
License
MIT
Repository
github
Last release
5 years ago

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