From 259d1c1aab1db202a19801d514f43b8f24ac1be1 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 6 May 2024 10:29:12 +0800 Subject: [PATCH] automatically execute recursion, with the data selection inline --- scripts/utils/nested.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/utils/nested.js b/scripts/utils/nested.js index 48e4dcd..ac6bb80 100644 --- a/scripts/utils/nested.js +++ b/scripts/utils/nested.js @@ -19,16 +19,16 @@ nested.dictionary = class dictionary { // Pull the data out. if (DATA != null && DATA != undefined && PATH[`all`].length) { - PATH[`remain`] = PATH[`all`]; + PATH[`remain`] = [...PATH[`all`]]; PATH[`selected`] = String(PATH[`remain`].shift()).trim(); // Get the selected data. - DATA = DATA[PATH[`selected`]]; - - // must run if there is actually a parameter to test - if (PATH[`remain`].length > 0) { - // Recursively run to make use of the existing data. - DATA = nested.dictionary.get(DATA, PATH[`remain`]); + if (Object.hasOwn(DATA, PATH[`selected`])) { + DATA = (PATH[`remain`].length) + ? nested.dictionary.get(DATA[PATH[`selected`]], PATH[`remain`]) + : DATA[PATH[`selected`]]; + } else if (!Object.hasOwn(DATA, PATH[`selected`])) { + DATA = null; }; };