dynamic-lib-loader
v1.0.4
Published
dynamically load lib folder files
Downloads
4
Readme
dynamic-lib-loader
Load multiple files into a project by a simple short line
var lib = libLoader(__dirname+"/lib");
tree
|- main.js
|- lib
| |- a.js
| |- b.js
lib/a.js
module.exports = 1;
lib/b.js
module.exports = 2
main.js
const libLoader = require("dynamic-lib-loader");
var lib = libLoader(__dirName+"\lib");
console.log(lib); // => { a: 1, b: 2 }
#Reducer Reducers allows you to change the way libLoader loads the files.
var reducer = function(item, res){}
the default reducer:
var defaultLoaderReducer = function( {name, filePath, ext}, res = {} ){
res[name] = require(filePath);
return res;
}
load files as an array:
var reduceList = (item, res=[]) => res.concat( require(item.filePath) )
using a reducer:
const libLoader = require("dynamic-lib-loader");
var reducer = (item, res=[]) => res.concat( require(item.filePath) );
var lib = libLoader( __dirName+"\lib", reducer );
console.log(lib); // => [1,2]