0.1.0 • Published 7 years ago
batch-require v0.1.0
batch-require
Sometimes we wanna load a batch of module in a directory. When you have such demand, batch-require gives you a good choice.
How to use
├─long_modules
│ path_1_module.js
│ path_2_module.js
│ path_3_module.js
│
├─mocha
│ test.js
const path = require('path')
const {expect} = require('chai');
const batchRequire = require('batch-require');
class TestClass {
constructor(item) {
for (const key in item) {
this[key] = item;
}
}
}
const modules = batchRequire({
filenameSuffix:'_module.js',
basePath:path.join(__dirname,'../long_modules'),
keyReplaces:{'_':'/'}
});
expect(modules).to.have.property('path/1');
expect(modules['path/1']).to.be.an.instanceof(TestClass);
API
See the api document.
License
0.1.0
7 years ago