UNPKG

1 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/builtin/interopRequireDefault");
4
5exports.__esModule = true;
6exports.default = void 0;
7
8var _inherits = _interopRequireDefault(require("./util/inherits"));
9
10var _mixed = _interopRequireDefault(require("./mixed"));
11
12var _default = BooleanSchema;
13exports.default = _default;
14
15function BooleanSchema() {
16 var _this = this;
17
18 if (!(this instanceof BooleanSchema)) return new BooleanSchema();
19
20 _mixed.default.call(this, {
21 type: 'boolean'
22 });
23
24 this.withMutation(function () {
25 _this.transform(function (value) {
26 if (!this.isType(value)) {
27 if (/^(true|1)$/i.test(value)) return true;
28 if (/^(false|0)$/i.test(value)) return false;
29 }
30
31 return value;
32 });
33 });
34}
35
36(0, _inherits.default)(BooleanSchema, _mixed.default, {
37 _typeCheck: function _typeCheck(v) {
38 if (v instanceof Boolean) v = v.valueOf();
39 return typeof v === 'boolean';
40 }
41});
42module.exports = exports["default"];
\No newline at end of file