4.0.0 • Published 8 years ago

ensure-request v4.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

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.

4.0.0

8 years ago

3.2.1

8 years ago

3.2.0

8 years ago

3.1.0

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

1.2.0

8 years ago

1.1.0

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago