npm.io
0.2.1 • Published 2 years ago

yup-x

Licence
ISC
Version
0.2.1
Deps
12
Size
127 kB
Vulns
1
Weekly
0

YupX


      _____                    _____                    _____
     |\    \                  /\    \                  /\    \                 ______
     |:\____\                /::\____\                /::\    \               |::|   |
     |::|   |               /:::/    /               /::::\    \              |::|   |
     |::|   |              /:::/    /               /::::::\    \             |::|   |
     |::|   |             /:::/    /               /:::/\:::\    \            |::|   |
     |::|   |            /:::/    /               /:::/__\:::\    \           |::|   |
     |::|   |           /:::/    /               /::::\   \:::\    \          |::|   |
     |::|___|______    /:::/    /      _____    /::::::\   \:::\    \         |::|   |
     /::::::::\    \  /:::/____/      /\    \  /:::/\:::\   \:::\____\  ______|::|___|___ ____
    /::::::::::\____\|:::|    /      /::\____\/:::/  \:::\   \:::|    ||:::::::::::::::::|    |
   /:::/~~~~/~~      |:::|____\     /:::/    /\::/    \:::\  /:::|____||:::::::::::::::::|____|
  /:::/    /          \:::\    \   /:::/    /  \/_____/\:::\/:::/    /  ~~~~~~|::|~~~|~~~
 /:::/    /            \:::\    \ /:::/    /            \::::::/    /         |::|   |
/:::/    /              \:::\    /:::/    /              \::::/    /          |::|   |
\::/    /                \:::\__/:::/    /                \::/____/           |::|   |
 \/____/                  \::::::::/    /                  ~~                 |::|   |
                           \::::::/    /                                      |::|   |
                            \::::/    /                                       |::|   |
                             \::/____/                                        |::|___|
                              ~~                                               ~~

Quick Start

Check out our recipes repo to learn how everything works.

Description

YupX lets you deploy an API for your backend using just yup schemas.

Essentially, it does all the work to turn this:

const personSchema = yup.object({
  firstName: yup.string().defined(),
  nickName: yup.string().default('').nullable(),
  sex: yup
    .mixed()
    .oneOf(['male', 'female', 'other'] as const)
    .defined(),
  email: yup.string().nullable().email(),
  birthDate: yup.date().nullable().min(new Date(1900, 0, 1)),
});

Into this:

const express = require('express');
const yup = require('yup');
const router = express.Router();

// Create (POST)
router.post('/person', async (req, res) => {
	// ...
});

// Read (GET)
router.get('/person/:id', async (req, res) => {
	// ...
});

// Update (PUT)
router.put('/person/:id', async (req, res) => {
	// ...
});

// Delete (DELETE)
router.delete('/person/:id', async (req, res) => {
	// ...
});

module.exports = router;

Authors

License

BSD-3-Clause

Keywords