1 |
|
2 |
|
3 |
|
4 |
|
5 | var _ = require('lodash'),
|
6 | SchemaType = require('../schematype');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var SchemaBoolean = module.exports = function(options){
|
16 | SchemaType.call(this, options);
|
17 | };
|
18 |
|
19 | SchemaBoolean.type = SchemaBoolean.prototype.type = Boolean;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | SchemaBoolean.__proto__ = SchemaType;
|
26 | SchemaBoolean.prototype.__proto__ = SchemaType.prototype;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | SchemaBoolean.prototype.checkRequired = function(value){
|
37 | return value === true || value === false;
|
38 | };
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | SchemaBoolean.prototype.cast = function(value){
|
49 | if (value == null) return value;
|
50 | if ('0' === value) return false;
|
51 | if ('true' === value) return true;
|
52 | if ('false' === value) return false;
|
53 |
|
54 | return !!value;
|
55 | }; |
\ | No newline at end of file |