From 26c3455e97b6bfbc6b708694399c2345747ddf3d Mon Sep 17 00:00:00 2001 From: DigiLive Date: Thu, 1 May 2025 21:24:14 +0200 Subject: [PATCH] Add getValuesByProperty method to RegistryFilter - Introduced getValuesByProperty method to retrieve an array of values for a specified property from filtered entries. - This method enhances the functionality of the RegistryFilter class, allowing for more flexible data retrieval. --- src/utilities/RegistryFilter.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utilities/RegistryFilter.ts b/src/utilities/RegistryFilter.ts index bf331a5..e4472ec 100644 --- a/src/utilities/RegistryFilter.ts +++ b/src/utilities/RegistryFilter.ts @@ -408,6 +408,18 @@ class RegistryFilter { return fork.entries.filter((entry, index) => fork.filters.every((filter) => filter(entry, index))); } + /** + * Retrieves an array of values for a specified property from the filtered entries. + * + * @param {keyof T} propertyName - The name of the property whose values are to be retrieved. + * @returns {Array} An array of values corresponding to the specified property. + * If the property does not exist in any entry, those entries will be filtered out. + */ + getValuesByProperty(propertyName: keyof T): Array { + const entries = this.toList(); // Call toList to get the full entries + return entries.map((entry) => entry[propertyName]).filter((value) => value !== undefined) as Array; + } + /** * Applies all the accumulated filters to the entries and returns the first remaining entry. *