yuppers
a simple function to help generate yup validation schema
❗️ CAUTION
Quickly threw this together; only supports string and number data types
😎 INSTALL
$ yarn add yuppers
🔥 USAGE
Pass in a schema similar to something below:
const schema = {
// ...form properties
fields: [
{
key: 'name',
// ...other field properties
dataType: 'string',
validations: [
{
type: 'min',
value: 5,
message: 'Must have at least 5 chars'
}
]
},
{
key: 'password',
// ...other field properties
dataType: 'string',
required: true,
validations: [
{
type: 'min',
value: 8,
message: 'Must have at least 8 chars'
}
]
}
]
}
like so: validationBuilder(schema.fields)
to get:
yup.object().shape({
name: yup.string().min(5, 'Must have at least 5 chars'),
password: yup
.string()
.min(8, 'Must have at least 8 chars')
.required()
})
MIT