1 | # fs-of-type
|
2 |
|
3 | > wraps async.filter to find items of a particular type in a directory
|
4 |
|
5 | [![Build Status](https://travis-ci.org/kevmannn/fs-of-type.svg?branch=master)](https://travis-ci.org/kevmannn/fs-of-type)
|
6 |
|
7 | ## Install
|
8 |
|
9 | ```console
|
10 | npm install --save fs-of-type
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | const pathToContents = path.join(process.env.HOME, '/documents');
|
17 |
|
18 | fsOfType(pathToContents, 'file', (err, files) => {
|
19 | if (err) return cb(err);
|
20 |
|
21 | // => `files` is an array of the files in `pathToContents`
|
22 | cb(null, files);
|
23 | })
|
24 |
|
25 | fsOfType(pathToContents, ['directory', 'symbolicLink'], (err, result) => {
|
26 | if (err) return cb(err);
|
27 |
|
28 | // => `result` is an array of the dirs and symlinks in `pathToContents`
|
29 | cb(null, result);
|
30 | })
|
31 | ```
|
32 |
|
33 | ## API
|
34 |
|
35 | ### fsOfType(pathToContents, [type ...], callback)
|
36 |
|
37 | __Arguments__
|
38 |
|
39 | * `pathToContents` - a path (relative to your user home) which contains the items you wish to filter.
|
40 | * `type` - a string (or array of strings) representing the item type(s) you wish to filter by.
|
41 | The values of `type` must correspond to the names found in the [fs.Stats object](https://nodejs.org/api/fs.html#fs_class_fs_stats). (`file`, `directory`, `blockDevice`, `symbolicLink`, etc.)
|
42 | * `callback(err, results)` - a function to be invoked when the filtering has completed. `results` is an array of the items of type `type`.
|
43 |
|
44 | ## License
|
45 |
|
46 | MIT © [Kevin Donahue](https://twitter.com/recur_excur)
|