UNPKG

vtils

Version:

一个面向业务的 JavaScript/TypeScript 实用程序库。

69 lines (67 loc) 1.67 kB
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose"; import { anyToDate, isDate, isValid } from "../date/index.js"; import { VaeLocale } from "./VaeLocale.js"; import { VaeSchema } from "./VaeSchema.js"; export var VaeDateSchema = /*#__PURE__*/function (_VaeSchema) { _inheritsLoose(VaeDateSchema, _VaeSchema); function VaeDateSchema(message) { var _this; if (message === void 0) { message = VaeLocale.date.type; } _this = _VaeSchema.call(this, { type: 'date' }) || this; _this.transform(function (v) { return anyToDate(v); }).check({ fn: function fn(v) { return isDate(v) && isValid(v); }, message: message }); return _this; } /** * 最小日期 */ var _proto = VaeDateSchema.prototype; _proto.min = function min(value, message) { if (message === void 0) { message = VaeLocale.date.min; } var minDate = anyToDate(value); var minTime = minDate.getTime(); return this.check({ fn: function fn(v) { return minTime <= v.getTime(); }, message: message, messageParams: { min: minDate }, tag: 'min' }); } /** * 最大日期 */; _proto.max = function max(value, message) { if (message === void 0) { message = VaeLocale.date.max; } var maxDate = anyToDate(value); var maxTime = maxDate.getTime(); return this.check({ fn: function fn(v) { return maxTime >= v.getTime(); }, message: message, messageParams: { max: maxDate }, tag: 'max' }); }; return VaeDateSchema; }(VaeSchema);