Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/list-directories
List all directories in a given directory
https://github.com/shinnn/list-directories
async-await directory filesystem iterable javascript list nodejs promise set
Last synced: 26 days ago
JSON representation
List all directories in a given directory
- Host: GitHub
- URL: https://github.com/shinnn/list-directories
- Owner: shinnn
- License: isc
- Created: 2017-08-02T10:58:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-17T18:00:55.000Z (almost 6 years ago)
- Last Synced: 2024-04-23T22:55:10.144Z (7 months ago)
- Topics: async-await, directory, filesystem, iterable, javascript, list, nodejs, promise, set
- Language: JavaScript
- Size: 54.7 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# list-directories
[![npm version](https://img.shields.io/npm/v/list-directories.svg)](https://www.npmjs.com/package/list-directories)
[![Build Status](https://travis-ci.org/shinnn/list-directories.svg?branch=master)](https://travis-ci.org/shinnn/list-directories)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/list-directories.svg)](https://coveralls.io/github/shinnn/list-directories?branch=master)List all directories in a given directory
```javascript
const listDirectories = require('list-directories');/*
./my-dir/a: file
./my-dir/b: directory
./my-dir/c: symlink to a directory
./my-dir/d: directory
*/(async () => {
await listDirectories('my-dir');
/* => Set {
'/Users/example/my-dir/b',
'/Users/example/my-dir/d'
} */
})();
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
```
npm install list-directories
```## API
```javascript
const listDirectories = require('list-directories');
```### listDirectories(*dir*)
*dir*: `string` `Buffer` `URL` (directory path)
*options*: `Object` ([`readdir-sorted`](https://github.com/shinnn/readdir-sorted) options)
Return: `Promise>`The promise will be fulfilled with a [`Set`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set) of strings — absolute paths of all directories included in the given directory.
Options are directly passed to the underlying [`readdir-sorted`](https://github.com/shinnn/readdir-sorted#readdirsortedpath--options) to control the order of results.
```javascript
listDirectories('/dirs').then(files => {
const iterator = files[Symbol.iterator];iterator.next().value; //=> '/dirs/10'
iterator.next().value; //=> '/dirs/2a'
iterator.next().value; //=> '/dirs/2A'
});listDirectories('/dirs', {
numeric: true,
caseFirst: 'upper'
}).then(files => {
const iterator = files[Symbol.iterator];iterator.next().value; //=> '/dirs/2A'
iterator.next().value; //=> '/dirs/2a'
iterator.next().value; //=> '/dirs/10'
});
```## License
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe