Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shinnn/readdir-clean

Like `fs.readdir`, but excludes autogenerated contents for example .DS_Store and Thumbs.db
https://github.com/shinnn/readdir-clean

filesystem filter javascript list nodejs promise readdir

Last synced: 27 days ago
JSON representation

Like `fs.readdir`, but excludes autogenerated contents for example .DS_Store and Thumbs.db

Awesome Lists containing this project

README

        

# readdir-clean

[![npm version](https://img.shields.io/npm/v/readdir-clean.svg)](https://www.npmjs.com/package/readdir-clean)
[![Build Status](https://travis-ci.com/shinnn/readdir-clean.svg?branch=master)](https://travis-ci.com/shinnn/readdir-clean)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/readdir-clean.svg)](https://coveralls.io/github/shinnn/readdir-clean?branch=master)

Like [`fs.promises.readdir()`](https://nodejs.org/api/fs.html#fs_fspromises_readdir_path_options) but excludes autogenerated contents for example `.DS_Store` and `Thumbs.db`

```javascript
const {readdir} = require('fs').promises;
const readdirClean = require('readdir-clean');

(async () => {
await readdir('.');
/*=> [
'.DS_Store',
'.AppleDouble',
'.LSOverride',
'a.txt',
'b.txt',
'Thumbs.db'
] */

await readdirClean('.');
/*=> [
'a.txt',
'b.txt'
] */
})();
```

## Installation

[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).

```
npm install readdir-clean
```

## API

```javascript
const readdirClean = require('readdir-clean');
```

### readdirClean(*path*)

*path*: `string | Buffer | Uint8Array | URL` (directory path)
Return: `Promise`

Similar to [Node.js](https://nodejs.org) built-in `fs.promises.readdir()`, but different in the following points:

* `encoding` option is not supported.
* The paths are filtered with [`require('junk').not`](https://github.com/sindresorhus/junk#junknotfilename).

```javascript
(async () => {
const paths = await readdirClean('path/to/dir');

paths.includes('.Spotlight-V100'); //=> false
paths.includes('.Trashes'); //=> false
paths.includes('Desktop.ini'); //=> false
})();
```

## License

[ISC License](./LICENSE) © 2017 - 2019 Shinnosuke Watanabe