UNPKG

838 BPlain TextView Raw
1/**
2 * Copyright (c) 2017 ~ present NAVER Corp.
3 * billboard.js project is licensed under the MIT license
4 */
5import {isDefined, isObjectType} from "../module/util";
6import Options from "./Options/Options";
7
8/**
9 * Load configuration option
10 * @param {object} config User's generation config value
11 * @private
12 */
13export 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}