export type RecordKey = string | number | symbol; export type JsonFilterCallback = (entry: [keyof T, T[keyof T]], index: number, array: [keyof T, T[keyof T]][]) => entry is [keyof T, T[keyof T]]; /** * Represents a valid key for an object, which can be a string, number, or symbol. * @typedef {string|number|symbol} RecordKey */ /** * A predicate function used to filter object entries. It receives the current entry as a [key, value] tuple, * the current index, and the array of all entries. It must act as a type guard to ensure the entry maintains the * correct tuple structure. * * @template T * @typedef {( * entry: [keyof T, T[keyof T]], * index: number, * array: [keyof T, T[keyof T]][] * ) => entry is [keyof T, T[keyof T]]} JsonFilterCallback */ /** * @template {Record} T * @param {T} value - The source object to be filtered. * @param {JsonFilterCallback} filterContent - Predicate function used to filter the object's entries. * @returns {Partial} - A new object containing a subset of the original object's keys. * @throws {TypeError} If the value is not a non-null object or filterContent is not a function. */ export declare function jsonFilter>(value: T, filterContent: JsonFilterCallback): Partial; export type BasePredicate = (current: T, index: number, array: any[]) => boolean; export type FilterOptions = { /** * - A predicate function applied to primitive values. Receives the entry as a `[key, value]` tuple. */ value?: BasePredicate<[any, any]>; /** * - A predicate function applied to nested objects, Maps, or Sets. Receives the filtered sub-structure as its first argument. */ obj?: BasePredicate | Map | Set>; /** * - A predicate function applied to array elements. Receives the entry as a `[key, value]` tuple. */ array?: BasePredicate<[any, any]>; }; /** * A predicate function used to determine whether an element should be included in the filtered result. * * @template T * @callback BasePredicate * @param {T} current - The current element being evaluated. Depending on the recursion level, this can be an entry tuple `[key, value]`, a primitive value, or a nested object. * @param {number} index - The zero-based index of the current element within the array being iterated. * @param {any[]} array - The array containing the current element. * @returns {boolean} True if the element satisfies the condition and should be kept; otherwise, false. */ /** * Configuration object for the `jsonFilterRecursive` function, containing predicate functions for different data types. * * @typedef {Object} FilterOptions * @property {BasePredicate<[any, any]>} [value] - A predicate function applied to primitive values. Receives the entry as a `[key, value]` tuple. * @property {BasePredicate | Map | Set>} [obj] - A predicate function applied to nested objects, Maps, or Sets. Receives the filtered sub-structure as its first argument. * @property {BasePredicate<[any, any]>} [array] - A predicate function applied to array elements. Receives the entry as a `[key, value]` tuple. */ /** * Recursively traverses an object and returns a new structure containing only the elements * that satisfy the provided filtering criteria. * * The function applies specific predicates based on the type of the current value: * 1. If the value is an Array, the `filter.array` predicate is applied. * 2. If the value is a Map or Set, the recursion occurs, and then the `filter.obj` predicate is applied to the result. * 3. If the value is an Object, the function recurses, and then the `filter.obj` predicate is applied to the result. * 4. If the value is a primitive, the `filter.value` predicate is applied. * * @template {Record} T * @param {T} value - The source object to be deeply filtered. * @param {FilterOptions} filter - An object containing optional predicate functions for different data types. * @returns {Partial} A new, deeply filtered version of the original object. * @throws {TypeError} If `filter.obj`, `filter.value`, or `filter.array` are provided but are not functions. */ export declare function jsonFilterRecursive>(value: T, filter: FilterOptions): Partial; export type ValueTypeValidator = (value: any) => boolean; /** * A predicate function used to validate whether a given value satisfies a specific condition or type requirement. * @typedef {(value: any) => boolean} ValueTypeValidator */ /** * @template {Record} T * @param {T} item - The source object to be filtered. * @param {(RecordKey|[any, any|ValueTypeValidator])[]} keys - An array of keys or [key, value/validator] tuples to keep. * @param {(any|ValueTypeValidator)[]} [values] - An array of values or validators to validate against when using simple keys. * @returns {Partial} - A new object containing only the specified keys. * @throws {TypeError} If the item is not a non-null object, keys is not an array, or values is not an array. */ export declare function jsonFilterByKeys>(item: T, keys: (RecordKey | [any, any | ValueTypeValidator])[], values?: (any | ValueTypeValidator)[]): Partial; //# sourceMappingURL=jsonFilter.d.mts.map