UNPKG

react-chrono

Version:
48 lines 1.93 kB
/** * Utility functions for handling optional props and conditional spreading */ /** * Creates an object with only the defined (non-undefined) properties * @param props - Object with potentially undefined values * @returns Object with only defined values */ export declare function filterDefinedProps<T extends Record<string, unknown>>(props: T): Partial<T>; /** * Creates an object with only the truthy properties * @param props - Object with potentially falsy values * @returns Object with only truthy values */ export declare function filterTruthyProps<T extends Record<string, unknown>>(props: T): Partial<T>; /** * Conditionally includes props based on conditions * @param conditions - Object mapping prop names to their conditions and values * @returns Object with conditionally included props */ export declare function conditionalProps<T extends Record<string, unknown>>(conditions: Record<string, { condition: boolean; value: unknown; }>): Partial<T>; /** * More specific utility for the most common pattern in this codebase: * Include prop only if value is defined and not null */ export declare function includeIfDefined<T>(key: string, value: T): Record<string, T> | {}; /** * Include prop only if value is truthy */ export declare function includeIfTruthy<T>(key: string, value: T): Record<string, T> | {}; /** * Batch version for multiple props - most efficient for the timeline use case */ export interface PropCondition<T = any> { key: string; value: T; condition?: 'defined' | 'truthy' | boolean; } export declare function buildProps(conditions: PropCondition[]): Record<string, any>; /** * Simple object-based approach - most readable and maintainable */ export declare function pickDefined<T extends Record<string, any>>(obj: T): Partial<T>; export declare function pickTruthy<T extends Record<string, any>>(obj: T): Partial<T>; //# sourceMappingURL=propUtils.d.ts.map