neft
Version:
Universal Platform
29 lines (21 loc) • 531 B
text/coffeescript
# Optional Validator
Marks the property as optional.
An `undefined` and a `null` values are omitted.
```javascript
var schema = new Schema({
name: {
optional: true,
type: 'string'
},
text: {
type: 'string'
}
});
console.log(schema.validate({name: 'Max', text: 'Hello!'}));
// true
console.log(schema.validate({text: 'Hello!'}));
// true
console.log(utils.catchError(schema.validate, schema, [{name: 'Max'}])+'');
// "SchemaError: Required property text not found"
```
module.exports = (Schema) -> ->