Closed taylorreece closed 6 months ago
When sending payloads via HTTP client to an API, many paramaters are optional and we end up needing a series of spread operators when constructing the request payload. For example,
const body: CreateListBody = { name, ...(content && content.length && { content }), ...(dueDate !== undefined && { due_date: dueDate }), due_date_time: dueDateTime, ...(priority !== undefined && { priority }), ...(assigneeInt !== undefined && { assignee: assigneeInt }), ...(status && status.length && { status }), };
This could be simplified with the new cleanObject function:
cleanObject
const body: CreateListBody = util.types.cleanObject({ name, content, due_date: dueDate, due_date_time: dueDateTime, priority, assignee: assigneeInt, status })
The cleanObject function defaults to removing properties with values undefined, null or "", but any predicate can be passed in. For example:
undefined
null
""
cleanObject({foo: 1, bar: 2, baz: 3}, v => v % 2 === 0) // { foo: 1, baz: 3 }
When sending payloads via HTTP client to an API, many paramaters are optional and we end up needing a series of spread operators when constructing the request payload. For example,
This could be simplified with the new
cleanObject
function:The
cleanObject
function defaults to removing properties with valuesundefined
,null
or""
, but any predicate can be passed in. For example: