d-list
v1.0.1
Published
Read the contents of a directory with filters. Provides wrappers to `fs.readdir` to return just files or directories.
Downloads
1
Maintainers
Readme
d-list
Node.js module to read the contents of a directory with filters. Provides wrappers to fs.readdir
to return just files or directories.
Installation
npm install d-list
Usage
- getDirs(path)
- Like
fs.promises.readdir(path)
but only returns directories
- Like
- getDirsSync(path)
- Like
fs.readdirSync(path)
but only returns directories
- Like
- getFiles(path)
- Like
fs.promises.readdir(path)
but only returns directories
- Like
- getFilesSync(path)
- Like
fs.readdirSync(path)
but only returns directories
- Like
Async examples
example/
├── some_items/
├── another_dir/
├── foo.txt
└── bar.txt
import dl from 'd-list'
const path = 'example'
dl.getDirs(path).then(dirList => {
console.log(dirList)
// ['some_items', 'another_dir']
})
dl.getFiles(path).then(fileList => {
console.log(fileList)
// ['foo.txt', 'bar.txt']
})
Sync examples
example/
├── some_items/
├── another_dir/
├── foo.txt
└── bar.txt
import dl from 'd-list'
const path = 'example'
const dirList = dl.getDirsSync(path)
console.log(dirList)
// ['some_items', 'another_dir']
const fileList = dl.getFilesSync(path)
console.log(fileList)
// ['foo.txt', 'bar.txt']