vtils
Version:
一个面向业务的 JavaScript/TypeScript 实用程序库。
110 lines (105 loc) • 2.34 kB
JavaScript
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import { isArray } from "../utils/index.js";
import { VaeLocale } from "./VaeLocale.js";
import { VaeSchema } from "./VaeSchema.js";
export var VaeArraySchema = /*#__PURE__*/function (_VaeSchema) {
_inheritsLoose(VaeArraySchema, _VaeSchema);
function VaeArraySchema(element, message) {
var _this;
if (message === void 0) {
message = VaeLocale.array.type;
}
_this = _VaeSchema.call(this, {
type: 'array'
}) || this;
_this.check({
fn: isArray,
message: message
});
if (element) {
_this.element(element);
}
return _this;
}
/**
* 数组元素定义
*/
var _proto = VaeArraySchema.prototype;
_proto.element = function element(_element) {
return this.check({
fn: _element,
message: '',
tag: 'element'
});
}
/**
* 数组非空,即长度应大于 0
*/;
_proto.nonempty = function nonempty(message) {
if (message === void 0) {
message = VaeLocale.array.nonempty;
}
return this.check({
fn: function fn(v) {
return v.length > 0;
},
message: message,
tag: 'nonempty'
});
}
/**
* 数组最小长度
*/;
_proto.min = function min(value, message) {
if (message === void 0) {
message = VaeLocale.array.min;
}
return this.check({
fn: function fn(v) {
return v.length >= value;
},
message: message,
messageParams: {
min: value
},
tag: 'min'
});
}
/**
* 数组最大长度
*/;
_proto.max = function max(value, message) {
if (message === void 0) {
message = VaeLocale.array.max;
}
return this.check({
fn: function fn(v) {
return v.length <= value;
},
message: message,
messageParams: {
max: value
},
tag: 'max'
});
}
/**
* 数组固定长度
*/;
_proto.length = function length(value, message) {
if (message === void 0) {
message = VaeLocale.array.length;
}
return this.check({
fn: function fn(v) {
return v.length === value;
},
message: message,
messageParams: {
length: value
},
tag: 'length'
});
};
return VaeArraySchema;
}(VaeSchema);