Code Monkey home page Code Monkey logo

yup-ast's Introduction

yup-ast

Latest Stable Version Node.js Package NPM Downloads dependencies Status Test Coverage

Generates yup instances from JSON schemas.

This project is meant to be a successor to the original yup-ast which - due to licensing issues - can no longer be actively maintained. Due to time contraints, only the core functionality has been ported so far. Feel free to add any potential improvements or missing APIs from the original via PRs!

Installation

npm install --save @demvsystems/yup-ast

Usage

ES5

var transformAll = require('@demvsystems/yup-ast').transformAll;

ES2015+

import { transformAll } from '@demvsystems/yup-ast';

Transforming JSON to a schema instance

The JSON representation of a yup schema is an array with each call being an array again. The method calls start with "yup.". Each parameter is an additional array entry afterwards.

Example: To create a schema like the following:

const schema = yup.array()
  .required()
  .min(2)
  .of(
    yup.object()
      .required()
      .shape({
        foo: yup.string().required(),
      })
  );

you call transformAll like this:

const schema = transformAll([
  ['yup.array'],
  ['yup.required'],
  ['yup.min', 2],
  ['yup.of', [
    ['yup.object'],
    ['yup.required'],
    ['yup.shape', {
      foo: [['yup.string'], ['yup.required']],
    }],
  ]],
]);

Both can be validated the same way:

schema.isValidSync([
  { foo: 'bar' },
  { foo: 'baz' },
]); // => true

For more example use cases, have a look at the included test cases.

Changelog

Please look at the releases for more information on what has changed recently.

Credits

License

The ISC License (ISC). Please see License File for more information.

yup-ast's People

Contributors

atassis avatar dependabot[bot] avatar spaceemotion avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.