Created
March 22, 2018 15:47
-
-
Save diegohaz/5751b713e7b6be286caff365e15cab6e 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
const schema = require("schm"); | |
const Joi = require("joi"); | |
const joiValidate = constraints => prevSchema => prevSchema.merge({ | |
validate(values) { | |
const parsed = prevSchema.parse(values); | |
return Joi.validate(parsed, constraints); | |
} | |
}); | |
const userSchema = schema( | |
{ username: String }, | |
joiValidate({ | |
username: Joi.string().alphanum().min(3).max(30).required() | |
}) | |
); | |
userSchema.validate({ username: 'ab' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment