From 901ad921c71c3cec63811c2229a8c1106b6ad7e0 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Tue, 14 May 2024 22:57:04 +0800 Subject: [PATCH] support merge of objects --- scripts/utils/nested.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/utils/nested.js b/scripts/utils/nested.js index ac6bb80..846c9c4 100644 --- a/scripts/utils/nested.js +++ b/scripts/utils/nested.js @@ -44,7 +44,7 @@ nested.dictionary = class dictionary { @param {object} value the value to be used @return {object} the data */ - static set(data, path, value) { + static set(data, path, value, options = {}) { let DATA = data, PATH = path, VALUE = value; // Convert path into an array if not yet set. @@ -59,7 +59,11 @@ nested.dictionary = class dictionary { (DATA[PATH[`current`]] == null) ? DATA[PATH[`current`]] = {} : false; DATA[PATH[`current`]] = nested.dictionary.set(DATA[PATH[`current`]], PATH[`target`], VALUE); } else { - DATA[PATH[`current`]] = VALUE; + if ((typeof DATA[PATH[`current`]]).includes(`obj`) && (typeof VALUE).includes(`obj`) && !Array.isArray(DATA[PATH[`current`]]) && !Array.isArray(VALUE) && DATA[PATH[`current`]] && VALUE && ((options && (typeof options).includes(`obj`)) ? (options[`strict`] || options[`override`]) : true)) { + Object.assign(DATA[PATH[`current`]], VALUE); + } else { + DATA[PATH[`current`]] = VALUE; + }; } // Return the value.