-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (32 loc) · 1015 Bytes
/
index.js
File metadata and controls
41 lines (32 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use strict";
const multiload = require("./src/index");
module.exports = function load(path, cfg) {
let modules;
if (typeof path !== "string" || !path) {
throw new Error("multiload: path has to be defined properly");
}
cfg = typeof cfg === "object" && !Array.isArray(cfg) ? cfg : {};
if (typeof cfg.extension === "string") {
modules = multiload.extensionLoad(path, cfg);
} else {
modules = multiload.defaultLoad(path, cfg);
}
if (cfg.decorate) {
multiload.decorate(modules, cfg);
}
if (cfg.exclude) {
modules = multiload.exclude(modules, cfg.exclude);
}
// check if there's at least one module that has been loaded
// otherwise throw an error
if (Object.keys(modules).length === 0) {
throw new Error("multiload: no modules found, check folder and options");
}
// we want to return the modules as an array
if (cfg.format === "array") {
return Object.keys(modules).map(function (key) {
return modules[key];
});
}
return modules;
};