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

wibe-validator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wibe-validator

Wibe Validator helper

latest
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

Wibe Validator

It's a wrapper on top of JSON Schema Validator which should help you validate data match easier and faster without a need for any setup. Only two things are needed: schema and data.

How to use

Synchronous validation:

const WV = require('wibe-validator');
const validators = WV.Schemas.create({
  user: require('./path/to/user_schemas.json')
});

class UserResource () {
  static create(req) {
    const validation = validators.user.validate(req.body);
    if (!validation.valid) {
      return {
        status: 400,
        // If validations ends with multiple errors, it will return only first
        // To access them all, look up property validation.errors
        message: validation.popError()
      }
    }
    return createUser(data);
  }
}

Asynchronous validation:

const WV = require('wibe-validator');
const validators = WV.Schemas.create({
  user: require('./path/to/user_schemas.json')
});

class UserResource () {
  static create(req) {
    return validators.user
      .validate(req.body)
      .promise()
      .then(data => createUser(data))
      .catch(error => {
        return {
          status: 400,
          message: error.message
        }
      })
  }
}

Predefined Types

When you create your own schema you can use some predefined types:

  • ObjectId - Mongo DB Object Id.
  • UUID - Universally unique identifier

Example:

const WV = require('wibe-validator');

module.export = {
  required: ['id'],
  properties: {
    id: WV.Types.ObjectId,
    name: {
	   type: 'string'
    },
};

FAQs

Package last updated on 23 May 2018

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