Created
February 16, 2018 12:38
-
-
Save cannap/db3fafa1136f53221b5a0399a2c81352 to your computer and use it in GitHub Desktop.
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
export default function validate (fieldValidator) { | |
const parseValidators = haye.fromPipe(fieldValidator.rule).toArray() | |
let validatorList = [] | |
parseValidators.forEach(function (validator) { | |
if (!validators.hasOwnProperty(validator.name)) { | |
throw new Error(`Validator not found: ${validator.name}`) | |
} | |
const message = get(fieldValidator, `messages.${validator.name}`) | |
validatorList.push({ | |
validate: validators[validator.name] || false, | |
args: validator.args, | |
message: message | |
? fieldValidator.messages[validator.name] | |
: defaultMessages[validator.name] | |
}) | |
}) | |
return validatorList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment