j2y
v0.1.13
Published
JSON to Yup or Yup as config lets you save Yup validation as YAML or JSON.
Downloads
26
Readme
JSON to YUP
Updated! - Teddy Wong
Installation
yarn add j2y/
npm install j2yWhat is Yup?
YUP is an amazing library for validation of object shapes.
What does this library do?
This library saves YUP validation schemas in plain Json objects.
Typescript types are included so that you can write them by hand with autocompletion.
Example:
Schema JSON:
const schema: JsonSchema = {
marketingConsent: {
type: "boolean",
},
email: {
type: "string",
nullable: true,
lowercase: true,
email: "This is not a valid email format",
when: {
anyOf: ["marketingConsent"],
is: true,
then: {
type: "string",
lowercase: true,
required: "Please supply your email if you want us to market to you",
},
},
},
};Data JSON:
{
"marketingConsent": true,
"email": "[email protected]"
}Result"
import {jsonToYup} from "j2y";
import data from "./data.json";
jsonToYup(schema).isValidSync(data);