readme styling

This commit is contained in:
eleith 2011-09-24 12:05:21 -07:00
parent 5af0386c75
commit d049420cfc
1 changed files with 49 additions and 49 deletions

View File

@ -55,63 +55,63 @@ validate objects (including http request params) against a schema. includes expr
schema for a simple object of one integer value
schema =
{
// [string] value for acceppted parameters of the object you want to test
"wins":
schema =
{
// [string (built in types) or function (custom types)] the type declaration for accepted values
"type": "int",
// [string (built in filters) or function (custom filters) or array (mix and match!)]
// OPTIONAL, filters to process and optionally modify values
"filters": ["trim", "toInt", custom_filter],
// [anything]
// OPTIONAL, the default value if none is supplied by the object
"default": 0,
// [boolean]
// OPTIONAL, if true, this parameter must exist to validate
"required": 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}
// [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
// keys can be any property key that was used as well as "filters", "required", "type"
"error": {max: "too many wins", min: "too few wins", "default": "something is wrong with your wins value"}
}
};
// [string] value for acceppted parameters of the object you want to test
"wins":
{
// [string (built in types) or function (custom types)] the type declaration for accepted values
"type": "int",
// [string (built in filters) or function (custom filters) or array (mix and match!)]
// OPTIONAL, filters to process and optionally modify values
"filters": ["trim", "toInt", custom_filter],
// [anything]
// OPTIONAL, the default value if none is supplied by the object
"default": 0,
// [boolean]
// OPTIONAL, if true, this parameter must exist to validate
"required": 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}
// [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
// keys can be any property key that was used as well as "filters", "required", "type"
"error": {max: "too many wins", min: "too few wins", "default": "something is wrong with your wins value"}
}
};
schema with embedded schemas for object and array types
schema =
{
"user":
schema =
{
"type": "object",
"schema":
"user":
{
"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"
},
"tags":
{
"type": "array",
"schema":
"type": "object",
"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"
},
"tags":
{
"type": "string"
"type": "array",
"schema":
{
"type": "string"
}
"properties": { max: 10, min: 3}
"error": { max: "too many tags", min: "too few tags" }
}
"properties": { max: 10, min: 3}
"error": { max: "too many tags", min: "too few tags" }
}
};
};
## schema.types