Omit Empty
omitEmpty removes empty properties from an object.
Build objects without conditional spreads
Objects can be simpler even when some properties are conditional.
No need to use conditional spreads or add them in later.
// Beforeconst author = { name: 'Zell Liew', ...(bio && { bio }),}// Afterconst author = omitEmpty({ name: 'Zell Liew', bio,})Cleans up nested values too
omitEmpty is recursive by default, so it removes empty values inside nested objects and arrays.
omitEmpty({ a: { one: {}, two: [], three: 1, },})
// {// a: {// three: 1,// },// }