1.0.3 • Published 2 years ago

@borisbelmar/yup-schema-generator v1.0.3

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

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
})
1.0.3

2 years ago

1.0.2

2 years ago