1.4.1 • Published 2 years ago

@zoodogood/import-directory v1.4.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

NPM, GITHUB

Dynamically imports all files from a directory.

Warning:
Supports only ES6 import*!

Basic usage

import { ImportDirectory } from '@zoodogood/import-directory';

const path = "./folder";

const modules = await new ImportDirectory() .import(path);

modules.forEach(moduleExport => /.../)

#### With details
```js
import { ImportDirectory } from '@zoodogood/import-directory';

// the example shows the default values
const options = {
  // Import one by one
  sync: true,

  // Import files from subfolders
  subfolders: false,

  // Ignore files not matching regular expression. Default all files that do not start with a dot and ending with `.js` or `ts`
  regex: /^[^.].*?\.(?:js|ts)$/i,

  // Call a function on every import
  callback: null,

  // Check if files are folders
  skipValidation: false,

  // Required for relative paths to work properly
  rootDirectory: process.cwd()
}

// Relative path from project root folder or absolute path.
const path = "./folder";


const importDirectory = new ImportDirectory(options);
const modules = await importDirectory.import(path);

for (const module of modules){
  // You will see the data exported from the file, equal to what you get with a normal import
  console.info(module);
}
1.5.1

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago