UNPKG

rhombus-node-mcp

Version:
29 lines (28 loc) 945 B
/** * Remove all null values from an object. * @param obj - The object to remove null values from. * @returns A new object with all null values removed. */ export function removeNulls(obj) { // Create a shallow copy to avoid modifying the original object const copy = { ...obj }; for (const key in copy) { if (Object.prototype.hasOwnProperty.call(copy, key)) { const value = copy[key]; if (value === null) { delete copy[key]; } else if (typeof value === "object" && value !== null && !Array.isArray(value)) { // Recursively clean nested objects const cleaned = removeNulls(value); if (Object.keys(cleaned).length === 0) { delete copy[key]; } else { copy[key] = cleaned; } } } } return copy; }