easy-validator
Simple object validator for NodeJS (as Symfony Annotation validation system)
Status
Installation
$ npm install easy-validator
To run the unit tests with mocha from your project :
npm test
Validating Objects
Sample of simple validating a not null string from an object :
var _ = ;var eValidator = ; //Creating sample objectvar objectToValidate = name: "Foo" email: "urodoz@gmail.com" age: 33; //Create the constraint collection (The name property should pass the 2 validations , NotNull and String typevar constraintCollection = eValidator; //Validate the object, and retrieve the list of errorsviolationList = constraintCollectionperform; //You can see all errors on the violationsList (array)_;
The same validation can be achieved wit object definition, instead string definition :
//String definition of the validatorsvar constraintCollection = eValidator;//The same object defined with object by each propertyvar constraintCollection = eValidator;
List of Asserts
@Assert:Email() For string values
Forces a value to be a valid email
Sample :
var constraintCollection = eValidator
No configuration
@Assert:NotNull()
Forces a value to be not null value, and to be defined. Will add an error to violation list if null or undefined
No configuration
@Assert:Null()
Forces a value to be null value, or be undefined. Will add an error to violation list if not null or defined
No configuration
@Assert:Range() For numeric values
Forces a value to be defined in a range of numbers. Should be between min and max configurations if defined. Both configuration 'min' and 'max' are optional configurations.
Sample :
var constraintCollection = eValidator
@Assert:Type()
Forces a value to be null value, or be undefined. Will add an error to violation list if not null or defined
Allowed configuration of type (default configured to 'string')
Sample for array type
var constraintCollection = eValidator
Allowed types :
- string
- array
- object
- boolean
- numeric
TODO
Keep implementing Asserts implemented on Symfony2 current validation system