From 579070733cf9605e96f045158ba56dcc5a9fdb80 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 2 Apr 2025 22:12:06 +1100 Subject: feat: define bar layout via config --- src/config/funcs.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/config/funcs.ts') diff --git a/src/config/funcs.ts b/src/config/funcs.ts index 253164e..5b9efa4 100644 --- a/src/config/funcs.ts +++ b/src/config/funcs.ts @@ -25,16 +25,20 @@ const isCorrectType = (v: any, type: string | string[] | number[], path: string) try { // Recursively check type const type = JSON.parse(arrType); - const valid = v.filter((item, i) => - Object.entries(type).some(([k, t]) => { - if (!item[k]) { - console.warn(`Invalid shape for ${path}[${i}]: ${JSON.stringify(item)} != ${arrType}`); - return false; - } - return !isCorrectType(item[k], t as any, `${path}[${i}].${k}`); - }) - ); - v.splice(0, v.length, ...valid); // In-place filter + if (Array.isArray(type)) { + v.splice(0, v.length, ...v.filter((item, i) => isCorrectType(item, type, `${path}[${i}]`))); + } else { + const valid = v.filter((item, i) => + Object.entries(type).some(([k, t]) => { + if (!item[k]) { + console.warn(`Invalid shape for ${path}[${i}]: ${JSON.stringify(item)} != ${arrType}`); + return false; + } + return !isCorrectType(item[k], t as any, `${path}[${i}].${k}`); + }) + ); + v.splice(0, v.length, ...valid); // In-place filter + } } catch { const valid = v.filter((item, i) => { if (typeof item !== arrType) { -- cgit v1.2.3-freya