@savi2w/yup-of-json
v1.0.0
Published
Convert JSON to a yup schema
Downloads
1
Readme
Yup of JSON
Convert JSON to a yup
schema
Usage
import parse from "@savi2w/yup-of-json";
Example
- JSON Schema
{
"addresses": {
"raw": "Kukuroo Mountain"
},
"age": 14,
"github": "https://github.com/savi2w",
"hunter": true,
"name": "Killua Zoldyck",
"role": null,
"tags": [
{
"label": "cute"
}
]
}
- Result
yup
.object()
.shape({
addresses: yup
.object()
.shape({ raw: yup.string().required() })
.noUnknown()
.required(),
age: yup.number().required(),
github: yup.string().required(),
hunter: yup.boolean().nullable(),
name: yup.string().required(),
role: yup.mixed().nullable(),
tags: yup
.array()
.of(
yup
.object()
.shape({ label: yup.string().required() })
.noUnknown()
.required()
)
.defined(),
})
.noUnknown()
.required();
License
This project is distributed under the MIT license