New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

validation-schema

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validation-schema

A schema-based validation middleware for JSON requests

latest
npmnpm
Version
2.0.1
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Validation Schema

Build Status Maintenance License: GPL v3 npm version

Documentation

About

validation-schema is a Mongoose inspired express middleware with the purpose of validating and sanitizing JSON requests. It supports custom validate/sanitize with asynchronous capabilities.

Note: validation-schema is still early in development and has many planned features, along with optimization improvements.

Install

npm install validation-schema

Example

A quick example of how validation-schema could be used. View the documentation.

const validationSchema = require('validation-schema')

app.post('/', validationSchema({
  username: {
    type: 'string', // Data type check
    required: [true, 'A username is required'],
    minlength: [5, 'Username must be at least 5 characters'],
    maxlength: [25, 'Username must be no more than 25 characters']
  },
  password: { // can use single values for a default error message
    type: 'string',
    required: true,
    minlength: 5 
  }
}), (req, res, next) => {
  // Detailed report of all errors
  // Shows error location, error type e.g 'maxlength' and error messages.
  console.log(req.valid.errors) 

  // Nicely formatted array of error messages
  console.log(req.valid.errorMessages) 

  // Validated and sanitized values
  console.log(req.valid.values)
})

FAQs

Package last updated on 04 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts