require-directory-async
v1.0.3
Published
require a directory asynchronously
Downloads
7
Maintainers
Readme
require-directory-async
require a directory asynchronously.
install
yarn add require-directory-async
npm i require-directory-async
feature
- offered async operation
- support typescript
- offered filter
fast use
// router/index.js
const requireDirectoryAsync = require('require-directory-async');
module.exports = requireDirectoryAsync(module);
- use in other file
const routerPromise = require('./router');
routerPromise.then((module) => {
console.log(module) // directory module
})
example
- add another directory
// router/index.js
const requireDirectoryAsync = require('require-directory-async');
module.exports = requireDirectoryAsync(module, {
addPath: ['../routerAddition']
});
- filter
// router/index.js
const requireDirectoryAsync = require('require-directory-async');
module.exports = requireDirectoryAsync(module, {
filter (module) {
// filter operation here
return module;
}
});
- set recurse
// router/index.js
const requireDirectoryAsync = require('require-directory-async');
module.exports = requireDirectoryAsync(module, {
recurse: false
});
run unit test
npm run test
yarn test
- for more detail, such as ts usage, please view
test/
.