1 |
|
2 |
|
3 |
|
4 |
|
5 | import {isDefined, isObjectType} from "../module/util";
|
6 | import Options from "./Options/Options";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export function loadConfig(config: Options): void {
|
14 | const thisConfig: Options = this.config;
|
15 | let target;
|
16 | let keys;
|
17 | let read;
|
18 |
|
19 | const find = () => {
|
20 | const key = keys.shift();
|
21 |
|
22 | if (key && target && isObjectType(target) && key in target) {
|
23 | target = target[key];
|
24 | return find();
|
25 | } else if (!key) {
|
26 | return target;
|
27 | }
|
28 |
|
29 | return undefined;
|
30 | };
|
31 |
|
32 | Object.keys(thisConfig).forEach(key => {
|
33 | target = config;
|
34 | keys = key.split("_");
|
35 | read = find();
|
36 |
|
37 | if (isDefined(read)) {
|
38 | thisConfig[key] = read;
|
39 | }
|
40 | });
|
41 | }
|