0.2.0 • Published 9 years ago

require-dir-promise v0.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

Build Status

Coverage Status

require-dir-promise

A promise-based require for directories, heavily inpired by require-dir.

Iterates (non-recursively for now) through a directory and requires all "requirable" files. Unline most synchronous modules, require-dir-promise returns a collection of promises that can be chained in .then(), .all() and other promise calls.

Example

Given this directory structure:

dir
+ a.js
+ b.json
+ c.coffee
+ d.txt

requireDir('./dir') will return promises with the following contents:

{file: 'a.js', contents: 'Content for file a.js'}, 

{file: 'b.json', contents: 'Contents of file b.json'}

And if CoffeeScript was registered, {file: 'c.coffee', contents: 'Contents of file c.coffee'} will also be returned.

Installation

npm install require-dir-promise

Usage

Iterating over the loaded files

var requireDir = require('require-dir-promise');
requireDir('./path/to/dir').map(function(f) {
    console.log(f.fileName);
});

License

MIT.