Compare commits

...

3 Commits

Author SHA1 Message Date
Derrick Hammer 2a1078a3a2
*Update dist 2022-12-19 13:49:11 -05:00
Derrick Hammer a3f3e157b9
*improve object path check 2022-12-19 13:48:39 -05:00
Derrick Hammer 785e0b836c
*Pass fallback to objectPath.get 2022-12-19 13:48:12 -05:00
2 changed files with 9 additions and 4 deletions

6
dist/index.js vendored
View File

@ -65,7 +65,9 @@ class Config {
for (const key of Object.keys(settings)) {
const value = json[key];
let keyPath = key.split(".");
let isArray = typeof parseInt(keyPath.pop()) === "number";
let isArray = key.includes(".") &&
keyPath.length > 1 &&
typeof parseInt(keyPath.pop()) === "number";
if (isArray) {
let itemPath = keyPath.join(".");
let item = this.get(itemPath, []);
@ -127,7 +129,7 @@ class Config {
}
(0, bsert_1.default)(typeof key === "string", "Key must be a string.");
key = this.normalize(key);
return object_path_1.default.get(this.data, key);
return object_path_1.default.get(this.data, key, fallback);
}
typeOf(key) {
const value = this.get(key);

View File

@ -77,7 +77,10 @@ export default class Config {
const value = json[key];
let keyPath = key.split(".");
let isArray = typeof parseInt(keyPath.pop()) === "number";
let isArray =
key.includes(".") &&
keyPath.length > 1 &&
typeof parseInt(keyPath.pop()) === "number";
if (isArray) {
let itemPath = keyPath.join(".");
@ -160,7 +163,7 @@ export default class Config {
key = this.normalize(key);
return objectPath.get(this.data, key);
return objectPath.get(this.data, key, fallback);
}
public typeOf(key: string) {