-
Notifications
You must be signed in to change notification settings - Fork 0
Utilities: FilterUtility
alessbarb edited this page Sep 17, 2023
·
2 revisions
File: filter.utility.ts
The FilterUtility class is a utility mixin designed to filter out unused or null properties from an object, returning a new, cleaner object. This class is particularly useful for data sanitization and object property management.
-
preservedProps: Set<string>: A set of properties that should never be removed during filtering. Default values include'name'and'message'.
Returns a new instance of the object with unused properties removed.
Usage Example:
const error = new ErrorEnhanced();
error.someField = null;
error.someOtherField = "usefulData";
const filteredError = error.filterUnused();
// filteredError now only contains 'someOtherField' and other useful properties.Checks if the given value is considered unused (e.g., null, undefined, etc.).
Checks if the given object is empty.
Checks if the given array is empty.
Checks if the given object is a plain object and if it is empty.
- Data Sanitization: Filtering out null or unused properties before saving an object to a database.
- Object Normalization: Creating a consistent object structure by removing unused or irrelevant fields.
error-enhanced Wiki
Version: 1.2.1 - © 2023
🔗 MIT License | 📦 GitHub Repository | 🐞 Report Issues | ✉️ Contact