@borisbelmar/yup-schema-generator
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Yup Schema Generator

codecov License: MIT install size

Generate Yup schemas from JSON Schema.

Installation

npm install @borisbelmar/yup-schema-generator

# or

yarn add @borisbelmar/yup-schema-generator

Basic Usage

import { generateYupSchema } from 'yup-schema-generator';

const schema = generateYupSchema({
  name: {
    type: 'string',
    required: true
  },
  age: {
    type: 'number',
    required: true,
    min: {
      value: 18,
      errorMessage: 'You must be at least 18 years old'
    }
  }
})

schema.isValid({
  name: 'John',
  age: 30,
}).then((valid) => {
  console.log(valid) // true
})

schema.isValid({
  name: 'John',
  age: 10,
}).catch((err) => {
  console.log(err) // ValidationError: You must be at least 18 years old
})

Readme

Keywords

none

Package Sidebar

Install

npm i @borisbelmar/yup-schema-generator

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

20.8 kB

Total Files

8

Last publish

Collaborators

  • borisbelmar