| Server IP : 14.225.204.176 / Your IP : 216.73.216.252 Web Server : nginx/1.24.0 System : Linux nodejs-ybgk 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024 x86_64 User : root ( 0) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/php/zinisoft.net-react/node_modules/yup/lib/ |
Upload File : |
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _has = _interopRequireDefault(require("lodash/has"));
var _isSchema = _interopRequireDefault(require("./util/isSchema"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Condition {
constructor(refs, options) {
this.fn = void 0;
this.refs = refs;
this.refs = refs;
if (typeof options === 'function') {
this.fn = options;
return;
}
if (!(0, _has.default)(options, 'is')) throw new TypeError('`is:` is required for `when()` conditions');
if (!options.then && !options.otherwise) throw new TypeError('either `then:` or `otherwise:` is required for `when()` conditions');
let {
is,
then,
otherwise
} = options;
let check = typeof is === 'function' ? is : (...values) => values.every(value => value === is);
this.fn = function (...args) {
let options = args.pop();
let schema = args.pop();
let branch = check(...args) ? then : otherwise;
if (!branch) return undefined;
if (typeof branch === 'function') return branch(schema);
return schema.concat(branch.resolve(options));
};
}
resolve(base, options) {
let values = this.refs.map(ref => ref.getValue(options == null ? void 0 : options.value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context));
let schema = this.fn.apply(base, values.concat(base, options));
if (schema === undefined || schema === base) return base;
if (!(0, _isSchema.default)(schema)) throw new TypeError('conditions must return a schema object');
return schema.resolve(options);
}
}
var _default = Condition;
exports.default = _default;