validation-error

1.0.0 • Public • Published

validation-error Build Status

A useful error container. It works well with monet's Validation applicative functor, but it may be used as a standalone library as well. For an example of its use with monet, checkout validation-example.

Install

$ npm install --save validation-error

Usage

var ValidationError = require('validation-error');
 
var ve = ValidationError.of("username", "username is invalid"); // preferred
// OR ValidationError("username", "username is invalid") 
// OR new ValidationError("username", "username is invalid")
 
// concatenate other validation errors 
var ve = ValidationError.of("username", "username is invalid");
var ve1 = ValidationError.of("email", "email is invalid")
var ve2 = ve.concat(ve1)
//=> object containg {username: "username is invalid, email: "email is invalid")
 

Review tests for a complete specification.

Interoperability

Fantasy Land

Conforms to the Fantasy Land Semigroup and Monoid interfaces.

API

.get(key)

Return the value associated with the key, or undefined if the key does not exist

.empty()

Returns the zero for this Monoid.

.concat(source, [source, ...])

Assigns enumerable own keys of source objects to a new ValidationError object and returns it. Additional source objects will overwrite previous ones. The current instance is not mutated.

.toArray()

Returns the values associated with this object's enumerable own-properties.

.toObject()

Returns a bare object containing enumerable own-properties of this object

.toJSON()

Returns a bare object containing enumerable own-properties of this object

License

MIT © Crisson Jno-Charles

Package Sidebar

Install

npm i validation-error

Weekly Downloads

29

Version

1.0.0

License

MIT

Last publish

Collaborators

  • crisson