@rxap/utilities
Version:
A collection of utility functions, types and interfaces.
32 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeleteEmptyProperties = DeleteEmptyProperties;
/* eslint-disable @typescript-eslint/ban-types */
const delete_undefined_properties_1 = require("./delete-undefined-properties");
const delete_null_properties_1 = require("./delete-null-properties");
/**
* Deletes all properties from an object that are either null or undefined.
*
* @template T - The type of the object. It must be an object type.
*
* @param {T} obj - The object from which to delete the properties. This object is not modified.
*
* @param {boolean} [recursive=false] - Optional. If true, the function will recursively delete null and undefined properties from all nested objects and arrays within the object. If false or omitted, the function will only delete null and undefined properties from the top level of the object.
*
* @returns {Exclude<Exclude<T, null>, undefined>} - A new object of the same type as the input object, but with all null and undefined properties removed. If the recursive option is true, all nested objects and arrays within the object will also have their null and undefined properties removed.
*
* @example
* // returns { a: 1, c: { d: 4 } }
* DeleteEmptyProperties({ a: 1, b: null, c: { d: 4, e: undefined } }, true);
*
* @example
* // returns { a: 1, c: { d: 4, e: undefined } }
* DeleteEmptyProperties({ a: 1, b: null, c: { d: 4, e: undefined } });
*
* @throws {TypeError} - If the input object is not an object.
*
*/
function DeleteEmptyProperties(obj, recursive) {
return (0, delete_undefined_properties_1.DeleteUndefinedProperties)((0, delete_null_properties_1.DeleteNullProperties)(obj, recursive), recursive);
}
//# sourceMappingURL=delete-empty-properties.js.map