fs-of-type
v1.1.8
Published
wraps `async.filter` to find items of a particular type in a directory
Downloads
27
Maintainers
Readme
fs-of-type
wraps
async.filter
to find items of a particular type in a directory
Install
npm install --save fs-of-type
Usage
const ofType = require('fs-of-type');
const pathToContents = path.join(process.env.HOME, 'documents');
ofType(pathToContents, 'file', (err, files) => {
// => `files` is an array of the files in `~/documents`
})
ofType(pathToContents, ['directory', 'symbolicLink'], (err, result) => {
// => `result` is an array of the dirs and symlinks in `~/documents`
})
API
ofType(pathToContents, [type ...], callback)
Arguments:
pathToContents
- a path (relative to your user home) which contains the items you wish to filter.type
- a string (or array of strings) representing the item type(s) you wish to filter by. The values oftype
must correspond to the names found in the fs.Stats object. (file
,directory
,blockDevice
,symbolicLink
, etc.)callback(err, results)
- a function to be invoked when the filtering has completed.results
is an array of the items of typetype
.
License
MIT © Kevin Donahue