1 | const register = (...args) => {
|
2 |
|
3 | let both = require('../both');
|
4 | let registerType = null;
|
5 | let registerName = null;
|
6 | let registerPayload = null;
|
7 |
|
8 |
|
9 | if (args.length < 2) {
|
10 | throw new Error('[both] the `register` module expects at least two arguments');
|
11 | }
|
12 |
|
13 | if (typeof args[0] !== 'string') {
|
14 | throw new Error('[both] the `register`module expects as first argument a registerType in string-format');
|
15 | } else {
|
16 | registerType = args[0];
|
17 | }
|
18 |
|
19 | if (args[1].toString() !== '[object Object]') {
|
20 | throw new Error('[both] the `register` module expects as second argument a object');
|
21 | } else {
|
22 | registerPayload = args[1];
|
23 | }
|
24 |
|
25 | if (registerPayload.name === undefined) {
|
26 | throw new Error('[both] the `register` module expets at least one `name` param in the given `registerObject`');
|
27 | } else {
|
28 | registerName = registerPayload.name;
|
29 | }
|
30 |
|
31 |
|
32 | both._globalRegistery[registerType] = both._globalRegistery[registerType] || {};
|
33 | both._globalRegistery[registerType][registerName] = registerPayload;
|
34 |
|
35 | };
|
36 |
|
37 | module.exports = register;
|