Compare commits
No commits in common. "e1d4785240c3815a5b0e376e96e0fb0edfd0c064" and "17a434f400f6425b854a8c1ff28af47e44b557f5" have entirely different histories.
e1d4785240
...
17a434f400
|
@ -64,6 +64,17 @@ class Config {
|
||||||
const settings = (0, deep_to_flat_object_1.default)(json);
|
const settings = (0, deep_to_flat_object_1.default)(json);
|
||||||
for (const key of Object.keys(settings)) {
|
for (const key of Object.keys(settings)) {
|
||||||
const value = settings[key];
|
const value = settings[key];
|
||||||
|
let keyPath = key.split(".");
|
||||||
|
let isArray = key.includes(".") &&
|
||||||
|
keyPath.length > 1 &&
|
||||||
|
typeof parseInt(keyPath.pop()) === "number";
|
||||||
|
if (isArray) {
|
||||||
|
let itemPath = keyPath.join(".");
|
||||||
|
let item = this.get(itemPath, []);
|
||||||
|
item.push(value);
|
||||||
|
this.set(itemPath, item);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this.set(key, value);
|
this.set(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +99,7 @@ class Config {
|
||||||
}
|
}
|
||||||
key = this.normalize(key);
|
key = this.normalize(key);
|
||||||
object_path_1.default.set(this.data, key, value);
|
object_path_1.default.set(this.data, key, value);
|
||||||
|
this.data[key] = value;
|
||||||
}
|
}
|
||||||
has(key) {
|
has(key) {
|
||||||
(0, bsert_1.default)(typeof key === "string", "Key must be a string.");
|
(0, bsert_1.default)(typeof key === "string", "Key must be a string.");
|
||||||
|
|
17
src/index.ts
17
src/index.ts
|
@ -75,6 +75,21 @@ export default class Config {
|
||||||
|
|
||||||
for (const key of Object.keys(settings)) {
|
for (const key of Object.keys(settings)) {
|
||||||
const value = settings[key];
|
const value = settings[key];
|
||||||
|
|
||||||
|
let keyPath = key.split(".");
|
||||||
|
let isArray =
|
||||||
|
key.includes(".") &&
|
||||||
|
keyPath.length > 1 &&
|
||||||
|
typeof parseInt(keyPath.pop()) === "number";
|
||||||
|
|
||||||
|
if (isArray) {
|
||||||
|
let itemPath = keyPath.join(".");
|
||||||
|
let item = this.get(itemPath, []);
|
||||||
|
item.push(value);
|
||||||
|
this.set(itemPath, item);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
this.set(key, value);
|
this.set(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,6 +123,8 @@ export default class Config {
|
||||||
key = this.normalize(key);
|
key = this.normalize(key);
|
||||||
|
|
||||||
objectPath.set(this.data, key, value);
|
objectPath.set(this.data, key, value);
|
||||||
|
|
||||||
|
this.data[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public has(key: string) {
|
public has(key: string) {
|
||||||
|
|
Loading…
Reference in New Issue