Skip to content

A useful error container for REST API and traditional webapp validation

License

Notifications You must be signed in to change notification settings

crisson/validation-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A useful error container for REST API and traditional webapp validation

Resources

License

Stars

Watchers

Forks

Packages

No packages published