UNPKG

3.42 kBMarkdownView Raw
1# lsr
2
3Recursive readdir (`ls -R`)
4
5[![Build Status](https://img.shields.io/travis/ForbesLindesay/lsr/master.svg)](https://travis-ci.org/ForbesLindesay/lsr)
6[![Dependency Status](https://img.shields.io/david/ForbesLindesay/lsr.svg)](https://david-dm.org/ForbesLindesay/lsr)
7[![NPM version](https://img.shields.io/npm/v/lsr.svg)](https://www.npmjs.com/package/lsr)
8
9## Installation
10
11 npm install lsr
12
13## Usage
14
15```js
16const {lsrSync, lsrAsync, lsrStream} = require('lsrc');
17// Synchronous
18console.dir(lsrSync(__dirname))
19
20// Promise
21lsrAsync(__dirname).then(function (res) {
22 console.dir(res)
23})
24
25// Stream
26lsrStream(__dirname).pipe(getPath()).pipe(process.stdout)
27```
28
29## API
30
31Each file system entry is represented by a [Stat](http://nodejs.org/api/fs.html#fs_class_fs_stats) object with the additional properties:
32
33 - `name`: the file name (e.g. `foo.txt`)
34 - `path`: the relative path to the file (e.g. `./subdir/foo.txt`). This is always separated by `/` regardless of platform.
35 - `fullPath`: the full path to the file (e.g. `c:\\basedir\\foo.txt` or `/basedir/foo.txt`). This is separated by the correct path separater for the platform.
36
37### lsrAsync(dir, options, callback)
38
39Recursively lists the files and folders and calls the callback exactly once with the error or null as the first argument and an array of file system entries as the second argument.
40
41Options:
42
43 - ignoreErrors - if any stat calls result in an error, simply ignore that item
44 - filter - a function that is called with a file sytem entry as its only argument and should return `true` to include that entry and any sub-entries in the result and `false` otherwise
45 - filterPath - a function that is called with the `path` property of the file system entry (before the call to `fs.stat`) as its only argument and should return `true` to include that entry and any sub-entries in the result and `false` otherwise
46
47If the callback is ommitted, a promise is returned instead.
48
49### lsrSync(dir, options)
50
51Recursively lists the files and folders and returns an array of file system entries.
52
53Options:
54
55 - ignoreErrors - if any stat calls result in an error, simply ignore that item
56 - filter - a function that is called with a file sytem entry as its only argument and should return `true` to include that entry and any sub-entries in the result and `false` otherwise
57 - filterPath - a function that is called with the `path` property of the file system entry (before the call to `fs.stat`) as its only argument and should return `true` to include that entry and any sub-entries in the result and `false` otherwise
58
59### lsrStream(dir, options)
60
61Recursively lists the files and folders and returns a stream of file system entries.
62
63Options:
64
65 - ignoreErrors - if any stat calls result in an error, simply ignore that item
66 - filter - a function that is called with a file sytem entry as its only argument and should return `true` to include that entry and any sub-entries in the result and `false` otherwise
67 - filterPath - a function that is called with the `path` property of the file system entry (before the call to `fs.stat`) as its only argument and should return `true` to include that entry and any sub-entries in the result and `false` otherwise
68 - highWaterMark - the maximum number of file system entries to buffer before it should stop calling `readdir` and `stat` while it waits for the consuming stream to catch up
69
70## License
71
72 MIT