0.1.13 • Published 3 years ago

j2y v0.1.13

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

JSON to YUP

Updated! - Teddy Wong

Installation

yarn add j2y

/

npm install j2y

What 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": "NOBODY@NOWHERE.COM"
}

Result"

import {jsonToYup} from "j2y";
import data from "./data.json";

jsonToYup(schema).isValidSync(data);
0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.6

3 years ago