UNPKG

aptx-validator

Version:

轻量易用的 Node.js + Typescript 参数校验库

82 lines (81 loc) 3.71 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _OrCondition_optional, _OrCondition_validators, _AndCondition_optional, _AndCondition_nullable, _AndCondition_validators; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidationException = exports.AndCondition = exports.OrCondition = void 0; const AllValidator_1 = __importDefault(require("./AllValidator")); const Utils_1 = require("./Utils"); class OrCondition extends AllValidator_1.default { constructor(validators) { super(); _OrCondition_optional.set(this, false); _OrCondition_validators.set(this, void 0); this.output = validators; __classPrivateFieldSet(this, _OrCondition_validators, validators, "f"); } optional() { __classPrivateFieldSet(this, _OrCondition_optional, true, "f"); return this; } test(p) { if ((0, Utils_1.isEmptyValue)(p)) { return __classPrivateFieldGet(this, _OrCondition_optional, "f"); } for (const v of __classPrivateFieldGet(this, _OrCondition_validators, "f")) { if (v.test(p)) return true; } return false; } } exports.OrCondition = OrCondition; _OrCondition_optional = new WeakMap(), _OrCondition_validators = new WeakMap(); class AndCondition extends AllValidator_1.default { constructor(validators) { super(); _AndCondition_optional.set(this, false); _AndCondition_nullable.set(this, false); _AndCondition_validators.set(this, void 0); this.output = validators; __classPrivateFieldSet(this, _AndCondition_validators, validators, "f"); } optional() { __classPrivateFieldSet(this, _AndCondition_optional, true, "f"); return this; } nullable() { __classPrivateFieldSet(this, _AndCondition_nullable, true, "f"); return this; } test(p) { if ((0, Utils_1.isEmptyValue)(p)) { return __classPrivateFieldGet(this, _AndCondition_optional, "f"); } for (const v of __classPrivateFieldGet(this, _AndCondition_validators, "f")) { if (!v.test(p)) return false; } return true; } } exports.AndCondition = AndCondition; _AndCondition_optional = new WeakMap(), _AndCondition_nullable = new WeakMap(), _AndCondition_validators = new WeakMap(); class ValidationException { constructor(v) { this.errMsg = ""; } } exports.ValidationException = ValidationException;