Created
October 25, 2019 13:36
-
-
Save wolframkriesing/1ed059f3351188bfe211ba22c96990bd to your computer and use it in GitHub Desktop.
better readable fn than listed here https://folktale.origamitower.com/api/v2.3.0/en/folktale.result.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const validateBranching = ({ name, type, email, phone }) => { | |
if (!isValidName(name)) | |
return Required('name'); | |
if (type === 'email') { | |
if (!isValidEmail(email)) | |
return InvalidEmail(email); | |
if (phone && !isValidPhone(phone)) | |
return Optional(InvalidPhone(phone)); | |
return { type, name, email, phone }; | |
} | |
if (type === 'phone') { | |
if (!isValidPhone(phone)) | |
return InvalidPhone(phone); | |
if (email && !isValidEmail(email)) | |
return Optional(InvalidEmail(email)); | |
return { type, name, email, phone }; | |
} | |
return InvalidType(type); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment