Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
directory-import
Advanced tools
Module sync or async import(requires) all modules from the folder you specify.
The module will allow you to sync or async import(requires) all modules from the folder you specify.
It's possible either to use modules from the returned object, or to execute a callback at each module
npm i directory-import
After install, you can require module:
const importDir = require('directory-import');
// Code
For example, we have the following directory structure:
In the code below, we gave several examples of how to import all modules into "someDir" directory and all its subdirectories.
const importDir = require('directory-import');
// EX 1
// Simple loading of all modules inside the directory and in all its subdirectories
importDir(`./someDir`, 'sync');
// EX 2
// Loading and working with all modules inside the directory and in all its subdirectories
importDir(`./someDir`, 'sync', (name, path, func) => {
console.info(
`name: ${name} \n` +
`path: ${path} \n` +
`func: ${func} \n`
);
// name: someFile1
// path: ./someDir/someFile1.js
// func: () => console.info('this is some file 1')
//
// name: someFile2
// path: ./someDir/someFile2.js
// func: () => console.info('this is some file 2')
//
// name: config
// path: ./someDir/config.json
// func: [object Object]
//
// name: someModule1
// path: ./someDir/someSubDir/someModule1.js
// func: () => console.info('this is some module 1')
//
// name: someModule2
// path: ./someDir/someSubDir/someModule2.js
// func: () => console.info('this is some module 2')
});
// EX 3
// The same as with the sync method above.
// However, modules load in order from fastest loaded to slowest loaded
importDir(`./someDir`, 'async', (name, path, func) => {
console.info(
`name: ${name} \n` +
`path: ${path} \n` +
`func: ${func} \n`
);
});
// EX 4
// Loading and storing modules in the object
const modulesSync = importDir(`./someDir`, 'sync');
console.info(modulesSync);
// {
// someFile1: [Function],
// someFile2: [Function],
// config: { some: 'text', author: 'kiidii' },
// someModule1: [Function],
// someModule2: [Function]
// }
// EX 5
// The same as with the sync method above.
// However, modules load in order from fastest loaded to slowest loaded
const modulesAsync = importDir(`./someDir`, 'async');
setTimeout(() => {
console.info(modulesAsync);
}, 1000);
You can easily combine this methods.
const modules = importDir(`./someDir`, 'sync', (name, path, func) => {
console.info(
`name: ${name} \n` +
`path: ${path} \n` +
`func: ${func} \n`
);
// name: someFile1
// path: ./someDir/someFile1.js
// func: () => console.info('this is some file 1')
//
// name: someFile2
// path: ./someDir/someFile2.js
// func: () => console.info('this is some file 2')
//
// name: config
// path: ./someDir/config.json
// func: [object Object]
//
// name: someModule1
// path: ./someDir/someSubDir/someModule1.js
// func: () => console.info('this is some module 1')
//
// name: someModule2
// path: ./someDir/someSubDir/someModule2.js
// func: () => console.info('this is some module 2')
});
console.info(modules);
// {
// someFile1: [Function],
// someFile2: [Function],
// config: { some: 'text', author: 'kiidii' },
// someModule1: [Function],
// someModule2: [Function]
// }
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official Discord server.
Although the server was created for Russian speakers, you can also write in English! We will understand you!
FAQs
Module will allow you to synchronously or asynchronously import (requires) all modules from the folder you specify
The npm package directory-import receives a total of 27,240 weekly downloads. As such, directory-import popularity was classified as popular.
We found that directory-import demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.