wraps `async.filter` to find items of a particular type in a directory


Keywords
async, blockDevice, characterDevice, dir, directory, directories, fifo, file, filter, fs, isDirectory, isFile, socket, symlink, typeof, filesystem
License
MIT
Install
npm install fs-of-type@1.0.7

Documentation

fs-of-type

npm version Build Status

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 of type 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 type type.

License

MIT © Kevin Donahue