Skip to content

pomelott/require-directory-async

Repository files navigation

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/.

About

require a directory asynchronously.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published