edited README

This commit is contained in:
Keith Abdulla 2014-08-23 18:52:03 -07:00
parent f894df37be
commit 22c62b7f05
1 changed files with 7 additions and 9 deletions

View File

@ -13,8 +13,6 @@ validate objects (including http request params) against a schema. includes expr
- schema is in JSON, making it portable
- properties, types and filters are extensible
# EXAMPLE USAGE - validate an object
```javascript
var schema = require("./path/to/schemajs");
var model = schema.create(
@ -62,7 +60,7 @@ app.get("/users", schema.middleware(query), function(req, res)
quickly test an individual schema
```javascript
field = schema.test("email@email.com", {type:"email", trim:true, properties:{min:5}})
field = schema.test("email@email.com", {type:"email", trim:true, properties:{min:5}});
```
## schema.create(schema)
@ -88,15 +86,15 @@ schema =
// [boolean]
// OPTIONAL, if true, this parameter must exist to validate
"required": true
"required": true,
// [boolean]
// OPTIONAL, if true, this parameter can be null, despite any other rules
"allownull": true
"allownull": true,
// [object]
// OPTIONAL, functions are custom property checks, else a built in property will be looked up
"properties": {max:100, min:0, special:custom_property}
"properties": {max:100, min:0, special:custom_property},
// [string, object] OPTIONAL, if there is an error, you can override the message that is returned
// use a string or the "default" key to use the default error message
@ -118,7 +116,7 @@ schema =
{
"name": { type: "string", properties: { max: 255 }, required: true},
"email": { type: "email", error: "email is not a valid email address"}
}
},
"error": "user needs an email and a name"
},
@ -128,8 +126,8 @@ schema =
"schema":
{
"type": "string"
}
"properties": { max: 10, min: 3}
},
"properties": { max: 10, min: 3},
"error": { max: "too many tags", min: "too few tags" }
}
};