syntax errors, added quick test for individual schemas
This commit is contained in:
parent
d67f81f32c
commit
a5e522d1a7
|
@ -57,6 +57,14 @@ app.get("/users", schema.middleware(query), function(req, res)
|
|||
```
|
||||
# API
|
||||
|
||||
## schema.test(schema)
|
||||
|
||||
quickly test an individual schema
|
||||
|
||||
```javascript
|
||||
field = schema.test("email@email.com", {type:"email", trim:true, properties:{min:5}})
|
||||
```
|
||||
|
||||
## schema.create(schema)
|
||||
|
||||
schema for a simple object of one integer value
|
||||
|
|
|
@ -325,7 +325,7 @@
|
|||
create: function(param, rules) { return new Rules(param, rules); },
|
||||
types: is,
|
||||
filters: filters,
|
||||
properties: checks,
|
||||
properties: checks
|
||||
};
|
||||
|
||||
var Schema = function(schema)
|
||||
|
@ -412,8 +412,9 @@
|
|||
|
||||
_.schema =
|
||||
{
|
||||
create: function(schema) { return new Schema(schema);},
|
||||
rules: rules
|
||||
test: function(value, schema) { return (new Schema({input:schema})).validate({input:value}); },
|
||||
create: function(schema) { return new Schema(schema);},
|
||||
rules: rules
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
@ -47,7 +47,7 @@ Schema.prototype.validate = function(data)
|
|||
}
|
||||
catch(error)
|
||||
{
|
||||
if(!errors[params[i]] || !(typeof(errors[params[i]]) == 'object'))
|
||||
if(!errors[params[i]] || typeof(errors[params[i]]) != 'object')
|
||||
errors[params[i]] = {};
|
||||
|
||||
errors[params[i]][param] = error;
|
||||
|
@ -84,6 +84,7 @@ Schema.prototype.validate = function(data)
|
|||
};
|
||||
|
||||
exports.types = rules.types;
|
||||
exports.test = function(value, schema) { return (new Schema({input:schema})).validate({input:value}); };
|
||||
exports.properties = rules.properties;
|
||||
exports.filters = rules.filters;
|
||||
exports.create = function(schema) { return new Schema(schema); };
|
||||
|
|
Reference in New Issue