Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

soc221b/yup-extra

Repository files navigation

yup-extra

yup-extra adds more useful methods that aren't included in the yup library

npm CI PRs welcome

Getting Started

Installation

npm install -S yup-extra

Import

On demand:

// Pattern: `yup-extra/${format}/${schema}/${method}`

// for ES6 Modules package
import 'yup-extra/es/string/json'

// for CommonJS package
require('yup-extra/lib/string/json')

API

string

string.json(type: AnySchema): Schema

Specify the schema of json.

import { string, number } from 'yup'
import 'yup-extra/es/string/json'

const value = JSON.stringify('foo')
const schema = string().json(number()).required()

schema.validate(value).catch(function (err) {
  console.log(err.name) // => 'ValidationError'
  console.log(err.errors) // => ['this must match given json schema']
  console.log(err.params.json.errors) // => ['this must be a `number` type, but the final value was: `NaN` (cast from the value `\"foo\"`).']
})

About

yup-extra adds more useful methods that aren't included in the yup library

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published