You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

ensure-request

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ensure-request

Validation for API requests

4.0.0
latest
Source
npm
Version published
Weekly downloads
7
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

ensure-request

Validation for API requests

npm version Codeship Status for stevejay/ensure-request Coverage Status bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies

NPM

Install

$ npm install --save ensure-request

Usage

const ensure = require('ensure-request');

const constraint = {
    name: {
        presence: true,
        string: true
    }
};

const request = {
    name: 123
};

// You can get a return value...
const errors = ensure(request, constraint); // null if no errors, an object of errors if not

// ... or pass an error handler function.
ensure(request, constraint, errors => { /* do what you like here, like throw */});

API

ensure(object, constraint)

Validates object according to the constraint object, throwing an Error exception if validation fails.

object

Type: Object

The object to validate.

constraint

Type: Object

The constraint object that specifies the constraints to apply to the object.

License

MIT

Acknowledgements

This package was heavily influenced by the package Validate.js. This package takes a different approach to how it walks nested objects and arrays, and how constraints are specified for them both.

Keywords

validation

FAQs

Package last updated on 04 Mar 2017

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