fs-of-type

1.1.8 • Public • Published

fs-of-type Build Status

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

License

MIT © Kevin Donahue

Package Sidebar

Install

npm i fs-of-type

Weekly Downloads

3

Version

1.1.8

License

MIT

Last publish

Collaborators

  • recursion_excursion