filter-files
Recursively read directories and return a list of files, filtered to have only the files for which the (optional) filter function returns
true
. Sync and async.
Install
npm
Install withnpm i filter-files --save
Run tests
npm test
Usage
var filter = ;
sync
filter;
Params
dir
{String}: the directory to start from. Returns all files, recursively, starting with this path.filterFn
{Function}: optionally pass a filter function to use for filtering files/dirs. This function filters "on the fly", so recursion is very fast.recurse
{Boolean}: passfalse
to disable recursion.
Examples
var files = filter;console;//=> [ 'lib/async.js', 'lib/filter.js', 'lib/sync.js' ]
Pass a filter function:
filter;//=> [ 'lib/async.js' ]
Or an array of filter functions:
{ return /^\./;} { return !/^\.[jntv]/;} // pass `false` to prevent recursion;//=> ['.git', '.gitignore', '.gitattribuets']
async
);
Params
Same as sync with the addition of callback
.
Examples
;
Pass a filter function:
var { return /a/;}; ;
Filtering
Filter functions take four parameters and return true
or false
.
Params
fp
filepath being looped overdir
current directoryfiles
accumulated array of filesrecurse
whether recurse istrue
orfalse
Example
This function returns a filter function for getting files with the given extname
:
var path = ;var isDir = ; { // this is our filter function return { if && recurse === true return true; return path === extname; }}
See the tests for more examples.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert
Released under the MIT license
This file was generated by verb on November 17, 2014.