feat: add form validation

This commit is contained in:
Divlo
2022-08-25 23:24:40 +02:00
parent c9bb631073
commit 17656c149a
13 changed files with 333 additions and 31 deletions

View File

@ -0,0 +1,17 @@
export const handleOptionalEmptyStringToNull = <K>(
object: K,
required: string[] = []
): K => {
return Object.fromEntries(
Object.entries(object).map(([key, value]) => {
if (
typeof value === 'string' &&
value.length === 0 &&
!required.includes(key)
) {
return [key, null]
}
return [key, value]
})
) as K
}