Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/read-glob-promise
Promise to read files with glob pattern
https://github.com/shinnn/read-glob-promise
Last synced: 26 days ago
JSON representation
Promise to read files with glob pattern
- Host: GitHub
- URL: https://github.com/shinnn/read-glob-promise
- Owner: shinnn
- License: mit
- Created: 2014-11-20T06:39:23.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-20T06:54:43.000Z (almost 10 years ago)
- Last Synced: 2024-09-25T16:55:41.468Z (about 2 months ago)
- Language: JavaScript
- Size: 160 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# read-glob-promise
[![Build Status](https://travis-ci.org/shinnn/read-glob-promise.svg?branch=master)](https://travis-ci.org/shinnn/read-glob-promise)
[![Build status](https://ci.appveyor.com/api/projects/status/09prv04d0ot3iitf?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/read-glob-promise)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/read-glob-promise.svg)](https://coveralls.io/r/shinnn/read-glob-promise)
[![Dependency Status](https://david-dm.org/shinnn/read-glob-promise.svg)](https://david-dm.org/shinnn/read-glob-promise)
[![devDependency Status](https://david-dm.org/shinnn/read-glob-promise/dev-status.svg)](https://david-dm.org/shinnn/read-glob-promise#info=devDependencies)[Promise] version of [read-glob](https://github.com/shinnn/node-read-glob):
> Search files with glob pattern and read them asynchronously
```javascript
var readGlob = require('read-glob-promise');readGlob('*.txt')
.then(function(bufs) {
bufs; //=> [, , ...]
})
.catch(function(err) {
console.log(err.message);
});
```## Installation
[![NPM version](https://badge.fury.io/js/read-glob-promise.svg)](https://www.npmjs.org/package/read-glob-promise)
[Use npm.](https://www.npmjs.org/doc/cli/npm-install.html)
```
npm install read-glob-promise
```## API
```javascript
var readGlob = require('read-glob-promise');
```### readGlob(*pattern* [, *options*])
*pattern*: `String` (glob pattern)
*options*: `Object` or `String`
Return: `Object` ([Promise])When it finish reading files, it will be [*fulfilled*](http://promisesaplus.com/#point-26) with an `Array` of file contents as its first argument.
When it fails to read the files, it will be [*rejected*](http://promisesaplus.com/#point-30) with an error as its first argument.
```javascript
var readGlob = require('read-glob-promise');// foo.txt: lorem
// bar.txt: ipsum
// baz.txt: dolorreadGlob('{foo,ba*}.txt', 'utf8')
.then(function(contents) {
contents; //=> ['lorem', 'ipsum', 'dolor']
});readGlob('{foo,bar.baz}.txt', {nobrace: true})
.then(function(contents) {
contents; //=> []
});
```#### options
The option object will be directly passed to [glob](https://github.com/isaacs/node-glob#options) and [fs.readFile], or the encoding string sets the encoding of [fs.readFile].
Unlike the original API, glob's `nodir` option is `true` by default.
## License
Copyright (c) 2014 [Shinnosuke Watanabe](https://github.com/shinnn)
Licensed under [the MIT License](./LICENSE).
[fs.readFile]: http://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback
[Promise]: http://promisesaplus.com/