validate / 2.1.5 last updated 3 months ago created on May 30th 2012
Install
npm install --save validate
Clone
git clone git@github.com:eivindfjeldstad/validate.git
dependencies
| main |
|
eivindfjeldstad-dot | 0.0.1 | MIT |
|
|
component-type | 1.0.0 | MIT | |
|
|
typecast | 0.0.1 | MIT |
maintainers
versions
21 total
| 2.1.5 | 3 months ago | eivifj |
| 2.1.4 | 3 months ago | eivifj |
| 2.1.3 | 4 months ago | eivifj |
| 2.1.2 | 7 months ago | eivifj |
| 2.1.1 | 8 months ago | eivifj |
| 2.1.0 | 8 months ago | eivifj |
| 2.0.1 | 8 months ago | eivifj |
| 2.0.0 | 8 months ago | eivifj |
| 1.1.1 | 9 months ago | eivifj |
| 1.1.0 | 9 months ago | eivifj |
| 1.0.1 | 9 months ago | eivifj |
| 1.0.0 | 9 months ago | eivifj |
| 0.2.4 | a year ago | eivifj |
| 0.2.3 | a year ago | eivifj |
| 0.2.2 | 2 years ago | eivifj |
| 0.2.1 | 2 years ago | eivifj |
| 0.2.0 | 2 years ago | eivifj |
| 0.1.3 | 2 years ago | eivifj |
| 0.1.2 | 2 years ago | eivifj |
| 0.1.1 | 2 years ago | eivifj |
| 0.1.0 | 2 years ago | eivifj |
readme
validate
Validate object properties in javascript.
Example
You can also add paths to a schema by using the chainable API
Typecasting
Values can be automatically typecasted before validation.
To enable typecasting, pass an options object to the schema constructor with typecast set to true.
You can override this setting by passing options to .validate()
To override
Property stripping
By default, all values not defined in the schema will be stripped from the object.
Set .strip = false on the options object to disable this behavior.
API
schema(paths, [opts])
Creates a new Schema with the given paths.
Schema#path(path, [rules])
Add path to schema with optional rules. Returns a Property.
Schema#validate(obj, [opts])
Validate given object. Returns an object containing an array of error messages,
.errors, and the accepted object, .accepted.
Schema#assert(obj, [opts])
Validate given object and throw if the validation fails. Returns the accepted object.
Property#use(fn, [msg])
Use the given validation function with and optional error message.
fn should accept a value and return true if the value is considered valid.
Property#type(name, [msg])
Property should be of type name.
Property#required(bool, [msg])
Property is required.
Property#match(regexp, [msg])
Proprety should match given regexp.
Property#message(msg)
Set default error message for property.
Licence
MIT