2.4.1 • Published 4 months ago

esm-import-directory v2.4.1

Weekly downloads
5
License
MIT
Repository
github
Last release
4 months ago

esm-import-directory

Import a directory of modules using es6 modules import

Usage

import path from 'path';
import importDirectory from 'esm-import-directory';

const dirname = path.dirname(import.meta.url.replace('file://', ''));

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

  // import with paths, eg. { 'filename.mjs': { hello: 'world' } }
  const typeDefPaths = await importDirectory(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 es6 modules. Default: true.
  • extensions (array) - the file extension types to process. Default: '.mjs'
2.4.1

4 months ago

2.4.0

1 year ago

2.3.8

2 years ago

2.3.7

2 years ago

2.3.6

2 years ago

2.3.5

2 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.0.0

3 years ago

1.4.0

3 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago