0.2.0 • Published 11 years ago
require-dir-promise v0.2.0
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.txtrequireDir('./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-promiseUsage
Iterating over the loaded files
var requireDir = require('require-dir-promise');
requireDir('./path/to/dir').map(function(f) {
console.log(f.fileName);
});License
MIT.
0.2.0
11 years ago