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.
$ npm install --save validation-error
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.
Conforms to the Fantasy Land Semigroup
and Monoid
interfaces.
Return the value associated with the key, or undefined if the key does not exist
Returns the zero for this Monoid.
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.
Returns the values associated with this object's enumerable own-properties.
Returns a bare object containing enumerable own-properties of this object
Returns a bare object containing enumerable own-properties of this object
MIT © Crisson Jno-Charles