esm-require-directory
TypeScript icon, indicating that this package has built-in type declarations

2.8.0 • Public • Published

esm-require-directory

Import a directory of modules using @std/esm

Usage

const path = require('path');
const requireDirectory = require('esm-require-directory');

(async function () {
  // import as array, eg. [{ hello: 'world' }]
  const typeDefs = await requireDirectory(path.join(__dirname, 'typeDefs'));

  // import with paths, eg. { 'filename.mjs': { hello: 'world' } }
  const typeDefPaths = await requireDirectory(path.join(__dirname, 'typeDefs'), {
    paths: true,
  });
})();

Options

  • recursive (boolean) - traverse modules recursively. Default: false.
  • paths (boolean) - modules returned as an object with relative paths vs as an array. Default: false.
  • filename (boolean) - only return the filename without the extension. Default: true for paths.
  • default (boolean) - extract default from esm modules. Default: true.
  • extensions (array) - the file extension types to process. Default: ['.mjs']

Package Sidebar

Install

npm i esm-require-directory

Weekly Downloads

24

Version

2.8.0

License

MIT

Unpacked Size

52.2 kB

Total Files

50

Last publish

Collaborators

  • kmalakoff