From 05eb2a2bedee54eba96e62072fb0dde37b1ced87 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Tue, 10 May 2022 19:08:16 -0500 Subject: [PATCH] Made findFeatures take multiple types, and added excludeFeatures --- src/features/feature.ts | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/features/feature.ts b/src/features/feature.ts index 2946726..65c03bb 100644 --- a/src/features/feature.ts +++ b/src/features/feature.ts @@ -60,13 +60,37 @@ export function setDefault( } } -export function findFeatures(obj: Record, type: symbol): unknown[] { +export function findFeatures(obj: Record, ...types: symbol[]): unknown[] { const objects: unknown[] = []; const handleObject = (obj: Record) => { Object.keys(obj).forEach(key => { const value = obj[key]; if (value && typeof value === "object") { - if ((value as Record).type === type) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if (types.includes((value as Record).type)) { + objects.push(value); + } else if (!(value instanceof Decimal) && !isRef(value)) { + handleObject(value as Record); + } + } + }); + }; + handleObject(obj); + return objects; +} + +export function excludeFeatures(obj: Record, ...types: symbol[]): unknown[] { + const objects: unknown[] = []; + const handleObject = (obj: Record) => { + Object.keys(obj).forEach(key => { + const value = obj[key]; + if (value && typeof value === "object") { + if ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + typeof (value as Record).type == "symbol" && + // eslint-disable-next-line @typescript-eslint/no-explicit-any + !types.includes((value as Record).type) + ) { objects.push(value); } else if (!(value instanceof Decimal) && !isRef(value)) { handleObject(value as Record);