yup-extra

1.0.0-alpha.1 • Public • Published

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\"`).']
})

Readme

Keywords

Package Sidebar

Install

npm i yup-extra

Weekly Downloads

1

Version

1.0.0-alpha.1

License

MIT

Unpacked Size

7.36 kB

Total Files

14

Last publish

Collaborators

  • iendeavor