import { type FilterFunction } from '../filter/filter'; import { type KeyAsString } from '../type'; /** * Callback invoked for each key/value tuple during iteration. */ export type ForEachKeyValueTupleFunction = (tuple: KeyValueTuple, index: number) => void; /** * Configuration for {@link forEachKeyValue} specifying a filter and a forEach callback. */ export interface ForEachKeyValue { readonly filter?: FilterKeyValueTuplesInput; readonly forEach: ForEachKeyValueTupleFunction; } /** * Iterates over filtered key/value tuples of an object and invokes a callback for each. * * @param obj - Object to iterate * @param config - Configuration with a forEach callback and optional filter * @param config.forEach - callback invoked for each key/value tuple that passes the filter * @param config.filter - optional filter controlling which key/value tuples are iterated; when omitted, all tuples are visited * * @example * ```ts * const keys: string[] = []; * forEachKeyValue({ a: 1, b: undefined, c: 3 }, { * filter: KeyValueTypleValueFilter.UNDEFINED, * forEach: ([key]) => keys.push(key as string) * }); * // keys: ['a', 'c'] * ``` */ export declare function forEachKeyValue(obj: T, { forEach, filter }: ForEachKeyValue): void; /** * Extracts key/value tuples from an object, optionally filtering them. * * @param obj - Object to extract tuples from * @param filter - Optional filter to apply to the tuples * @returns Array of matching key/value tuples * * @example * ```ts * const tuples = filterKeyValueTuples({ a: 1, b: null, c: 3 }, KeyValueTypleValueFilter.NULL); * // tuples: [['a', 1], ['c', 3]] * ``` */ export declare function filterKeyValueTuples(obj: T, filter?: FilterKeyValueTuplesInput): KeyValueTuple[]; /** * A Key-Value pair within an Tuple array value. */ export type KeyValueTuple = [K, T[K]]; /** * Function that extracts key/value tuples from an object, optionally filtering them based on a pre-configured filter. */ export type FilterKeyValueTuplesFunction = (obj: T) => KeyValueTuple[]; /** * Creates a reusable function that extracts and filters key/value tuples from objects. * * When no filter is provided, returns all key/value tuples. * * @param filter - Optional filter configuration * @returns A function that extracts filtered tuples from any input object * * @example * ```ts * const getDefinedTuples = filterKeyValueTuplesFunction(KeyValueTypleValueFilter.UNDEFINED); * const tuples = getDefinedTuples({ a: 1, b: undefined, c: 'hello' }); * // tuples: [['a', 1], ['c', 'hello']] * ``` */ export declare function filterKeyValueTuplesFunction(filter?: FilterKeyValueTuplesInput): FilterKeyValueTuplesFunction; /** * Returns all key/value pairs from the object as tuples using `Object.entries`. * * @param obj - Object to extract tuples from * @returns Array of `[key, value]` tuples * * @example * ```ts * const tuples = allKeyValueTuples({ x: 10, y: 20 }); * // tuples: [['x', 10], ['y', 20]] * ``` */ export declare function allKeyValueTuples(obj: T): KeyValueTuple[]; /** * Input for configuring key/value tuple filtering. Can be a {@link KeyValueTypleValueFilter} enum for simple cases * or a {@link KeyValueTupleFilter} object for more complex filtering (value type + key restriction + inversion). */ export type FilterKeyValueTuplesInput = KeyValueTypleValueFilter | KeyValueTupleFilter; /** * Value filter options for filterKeyValueTupleFunction() */ export declare enum KeyValueTypleValueFilter { /** * No filter */ NONE = 0, /** * Only undefined values. */ UNDEFINED = 1, /** * All values that are null or undefined. */ NULL = 2, /** * All values that are falsy. */ FALSY = 3, /** * All values that are empty. */ EMPTY = 4, /** * All values that are empty. Objects that have no keys are considered empty too. */ EMPTY_STRICT = 5, /** * All values that are falsy or empty. */ FALSY_AND_EMPTY = 6, /** * All values that are falsy or empty or an empty objects. */ FALSY_AND_EMPTY_STRICT = 7 } /** * Full configuration for filtering key/value tuples, supporting value type filtering, key restriction, and inversion. */ export interface KeyValueTupleFilter { /** * Type of value filtering to apply. */ valueFilter?: KeyValueTypleValueFilter; /** * When `true`, inverts the filter so that only non-matching tuples are retained. */ invertFilter?: boolean; /** * Restricts filtering to only these keys. Other keys are excluded from the result. */ keysFilter?: (K | KeyAsString)[]; } /** * Normalizes a {@link FilterKeyValueTuplesInput} to a {@link KeyValueTupleFilter} object. * * If the input is already an object, returns it as-is. If it's an enum value, wraps it in a filter object. * * @param input - Enum value or filter object * @returns Normalized filter object */ export declare function filterKeyValueTuplesInputToFilter(input: FilterKeyValueTuplesInput): KeyValueTupleFilter; /** * Predicate function that tests a single key/value tuple, returning `true` if it passes the filter. */ export type FilterKeyValueTupleFunction = FilterFunction>; /** * Creates a filter predicate function for key/value tuples based on the provided filter configuration. * * The predicate returns `true` for tuples whose values pass the configured filter. Supports value type filtering * (undefined, null, falsy, empty), key filtering, and inversion. * * @param inputFilter - Filter configuration (enum value or full config object) * @returns A predicate function that tests individual key/value tuples * * @example * ```ts * const isNotNull = filterKeyValueTupleFunction(KeyValueTypleValueFilter.NULL); * isNotNull(['a', 1], 0); // true * isNotNull(['b', null], 0); // false * ``` */ export declare function filterKeyValueTupleFunction(inputFilter: FilterKeyValueTuplesInput): FilterKeyValueTupleFunction;