JSPM

validatorjs-expressjs

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q27690F
  • License MIT

Validation library inspired by Laravel's Validator and support for express middleware

Package Exports

  • validatorjs-expressjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (validatorjs-expressjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Installation

Doc validatorjs

$ npm install validatorjs-expressjs

or

$ yarn add validatorjs-expressjs

Usage

Simple Usage

const express = require('express')
const validator = require('validatorjs-expressjs')
const app = express()
const Validator = require("validatorjs");

// IF YOU WANT TO ADD CUSTOM VALIDATE //
Validator.registerAsync("unique", async function(
    value,
    attribute,
    request,
    passes
) {
    passes()
});

app.use(validator({
    Validator
}))
// ------------------------------------

app.post('/products', [
    validator({
        rules:function (req) {
            name : "required",
            price : "required|numeric",
        }
    })
    function (req, res, next) {
        res.json({'message' : 'submit products ok'})
    }
])

app.use((err: any, req: any, res: any, next: any) => {
    res.status(400).json({
        message
    });
});

app.listen(80, function () {
  console.log('web server listening on port 80')
})

License

Copyright © 2012-2019 David Tang Released under the MIT license

Credits

validatorjs created by David Tang