UNPKG

@rxap/utilities

Version:

A collection of utility functions, types and interfaces.

31 lines (30 loc) 1.15 kB
/** * This function deletes null properties from an object and returns a new object with no null properties. * If the recursive flag is set, the function will recursively delete null properties from nested objects. * * @export * @template T extends {} A generic parameter that should be an object. * @param {T} obj The object from which null properties should be removed. * @param {boolean} [recursive=false] An optional boolean parameter indicating whether the function should recursively * remove null properties from nested objects. * @returns {Exclude<T, null>} The original object but without any null properties. * If the recursive flag is set, this includes nested objects. * * @example * * const inputObj = { * a: 1, * b: null, * c: { * d: 3, * e: null * } * } * * DeleteNullProperties(inputObj); * // Returns { a: 1, c: { d: 3, e: null } } * * DeleteNullProperties(inputObj, true); * // Returns { a: 1, c: { d: 3 } } */ export declare function DeleteNullProperties<T extends {}>(obj: T, recursive?: boolean): Exclude<T, null>;