fs-of-type
Filter a directory for all items of a given type
Install
npm i -S fs-of-type
Usage
import { join } from 'path';
import fsOfType from 'fs-of-type';
const pathToContents = join(process.env.HOME, 'documents');
fsOfType(pathToContents, 'file', (err, files) => {
// => `files` is an array of the files in `~/documents`
})
fsOfType(pathToContents, ['directory', 'symbolicLink'], (err, result) => {
// => `result` is an array of the dirs and symlinks in `~/documents`
})
API
fsOfType(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, result)
- a function to be invoked when the filtering has completed.result
is an array of the items of typetype
.
License
MIT © Kevin Donahue