Coder Social home page Coder Social logo

express-dry's Introduction

Express-Dry

A simple lightweight Express.js Validation Library (With predefined validators [WIP])

How to install

npm install express-dry

or

yarn add express-dry
  • Include in your project Eg. routes/auth.js
const { Router } = require('express')
const dry = require('express-dry')

const router = Router()

router.post('/login', dry.body({
  username: { type: String },
  password: { type: String },
  foo: { type: Boolean, required: false }
}), async (req, res) => {})

module.exports = router

After this the .body will return a middleware with packed automatic validation inside and it will directly return error response to client with a {message: ''} in it

  • Same with params and query
dry.params({ id: { type: Number } }, { allowExtraKeys: false })
dry.query({ search: { type: String, required: false } }, { allowExtraKeys: true, statusCode: 200 })

Features

  • All Javascript supported primitives
  • optional payload validation with required: false
  • Will be adding more custom validations such as Email, MongoObjectId and many more :)

Credits

@uditkarode for drytypes

License

MIT ©Swapnil Soni

express-dry's People

Contributors

swapnilsoni1999 avatar omeiirr avatar adarsh-chakraborty 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.