const findPath = require('{%= name %}');
findPath(filename, paths, options);
Params
filename
The filename or path to match. Passed to [path-ends-with][].paths
- an array of filepaths to match against.- options
Example
const paths = findPath('foo.md', ['a/b/c/foo.md', 'a/b/c/bar.md']);
console.log(paths);
//=> ['a/b/c/foo.md'];
Type: boolean
Default: undefined
Returns all of matched paths instead of only the first match.
const paths = [
'foo/bar/baz/about.md',
'foo/bar/baz/index.md',
'foo/bar/index.md',
'foo/bar/about.md',
'foo/bar/quux.md',
'foo/index.md',
];
console.log(findPath('index.md', paths));
//=> ['foo/bar/baz/index.md']
console.log(findPath('index.md', paths, { all: true }));
//=> ['foo/index.md', 'foo/bar/index.md', 'foo/bar/baz/index.md']
Type: boolean
Default: undefined
Sorts paths so that the first matching path with the fewest directory segments is returned. (note that options.all
is disabled when options.shortest
is true).
Example
const paths = [
'foo/bar/baz/about.md',
'foo/bar/baz/index.md',
'foo/bar/index.md',
'foo/bar/about.md',
'foo/bar/quux.md',
'foo/index.md',
];
console.log(findPath('index.md', paths));
//=> ['foo/bar/baz/index.md']
console.log(findPath('index.md', paths, { shortest: true }));
//=> ['foo/index.md']