Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takamin/files-async
This module creates a file list with reading a directory recursively. It can also callback each filename one by one. And the callback can be async.
https://github.com/takamin/files-async
Last synced: about 1 month ago
JSON representation
This module creates a file list with reading a directory recursively. It can also callback each filename one by one. And the callback can be async.
- Host: GitHub
- URL: https://github.com/takamin/files-async
- Owner: takamin
- License: mit
- Created: 2019-04-14T00:46:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-14T10:15:10.000Z (over 5 years ago)
- Last Synced: 2024-10-13T06:22:55.733Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# files-async
This module creates a file list with reading a directory recursively.
It can also callback each filename one by one.
And the callback can be async.## INSTALL
`npm install --save files-async`
## API
See [filesAsync](./lib/files-async.js).
This is the only one function that this module exports.## USAGE
Without a callback, the return value is an array of filename.
```javascript
const filesAsync = require("files-async");
(async ()=>{
const list = await filesAsync(dir);
}());
```You can receive a filename with a callback.
And the return value of the callback is pushed into the list that the method
will return.```javascript
const filesAsync = require("files-async");
const fs = require("fs");
(async ()=>{
const list = await filesAsync(dir,
pathname => fs.readFileSync(pathname));
}());
```The callback can return a Promise object.
```javascript
const filesAsync = require("files-async");
const fs = require("promise-fs");
(async ()=>{
const list = await filesAsync(dir,
pathname => fs.readFile(pathname));
}());
```And also it can be async.
```javascript
const filesAsync = require("files-async");
const fs = require("promise-fs");
(async ()=>{
const list = await filesAsync(dir,
async pathname => ({
pathname,
data: await fs.readFile(pathname),
})
);
}());
```## LICENSE
Copyright (c) 2019 Koji Takami
This software is released under the [MIT License](./LICENSE)