UNPKG

700 BJavaScriptView Raw
1import inherits from './util/inherits';
2import MixedSchema from './mixed';
3export default BooleanSchema;
4
5function BooleanSchema() {
6 var _this = this;
7
8 if (!(this instanceof BooleanSchema)) return new BooleanSchema();
9 MixedSchema.call(this, {
10 type: 'boolean'
11 });
12 this.withMutation(function () {
13 _this.transform(function (value) {
14 if (!this.isType(value)) {
15 if (/^(true|1)$/i.test(value)) return true;
16 if (/^(false|0)$/i.test(value)) return false;
17 }
18
19 return value;
20 });
21 });
22}
23
24inherits(BooleanSchema, MixedSchema, {
25 _typeCheck: function _typeCheck(v) {
26 if (v instanceof Boolean) v = v.valueOf();
27 return typeof v === 'boolean';
28 }
29});
\No newline at end of file