module importer from folder
npm install fd-importer!ignored.js).
require() та ESM import() (асинхронно).
{ filenameWithoutExt: exportedModule }.
bash
npm install fd-importer
``
---
📚 Використання
🔹 CommonJS (Node.js
require)
`js
const importer = require('fd-importer');
(async () => {
const modules = await importer('src/modules');
console.log(modules);
})();
`
---
🔹 ESM (Node.js
import)
`js
import importer from 'fd-importer';
const modules = await importer('src/modules');
console.log(modules);
`
---
⚙️ API
`ts
fdImporter(path, options?)
`
$3
| параметр | тип | опис |
| ---------------------- | --------- | ---------------------------------------------------------------------- |
| path | string | Шлях до директорії з модулями |
| options.blocked_char | string | Файли, що починаються з цього символу, пропускаються. (default: "!") |
| options.debug | boolean | Показувати повні помилки. (default: false) |
🧪 Приклад структури директорії
`
handlers/
login.js
logout.js
!ignore.js
`
$3
`js
{
login: require('./handlers/login.js'),
logout: require('./handlers/logout.js')
}
`
❗ Обмеження
* Імпортує лише файли першого рівня (без рекурсії).
* Працює тільки з файлами, які можна імпортувати через require() або import()`.