From 1905e6946350186256bf445306584843f4010cdc Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:29:21 +0100 Subject: [PATCH] Fixed settings test. --- src/node/utils/Settings.ts | 10 +++++++++- src/node/utils/SettingsTree.ts | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/node/utils/Settings.ts b/src/node/utils/Settings.ts index 78e592826..887aa284d 100644 --- a/src/node/utils/Settings.ts +++ b/src/node/utils/Settings.ts @@ -629,6 +629,12 @@ const lookupEnvironmentVariables = (obj: MapArrayType) => { * The environment variable expansion syntax "${ENV_VAR}" is just a string * of specific form, after all. */ + + if(key === 'undefined' || value === undefined) { + delete obj[key] + continue + } + if ((typeof value !== 'string' && typeof value !== 'object') || value === null) { obj[key] = value; continue @@ -723,7 +729,9 @@ const lookupEnvironmentVariables = (obj: MapArrayType) => { currentNode.addChild(pathToKey, value!) }) - console.log(root.collectFromLeafsUpwards()) + //console.log(root.collectFromLeafsUpwards()) + //const rooting = root.collectFromLeafsUpwards() + obj = Object.assign(obj, envVars) return obj; }; diff --git a/src/node/utils/SettingsTree.ts b/src/node/utils/SettingsTree.ts index c505f2ebb..33e2e5527 100644 --- a/src/node/utils/SettingsTree.ts +++ b/src/node/utils/SettingsTree.ts @@ -73,6 +73,23 @@ export class SettingsNode { return collected; } + + public transformObjectWithArrays() { + function isNumeric(str: string|object) { + if (typeof str != "string") return false // we only process strings! + // @ts-ignore + return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)... + !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail + } + let collected: MapArrayType = {}; + for (const key in this.children) { + if (isNumeric(key)) { + Object.entries(this.children).map(([key, value]) => { + }) + } + } + } + coerceValue = (stringValue: string) => { // cooked from https://stackoverflow.com/questions/175739/built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number // @ts-ignore