add all frontend files

This commit is contained in:
2026-01-17 15:16:36 -05:00
parent ff16ae7858
commit e40287e4aa
25704 changed files with 1935289 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import type { ExecuteRule } from '../interface';
declare const enumerable: ExecuteRule;
export default enumerable;

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _util = require("../util");
var ENUM = 'enum';
var enumerable = function enumerable(rule, value, source, errors, options) {
rule[ENUM] = Array.isArray(rule[ENUM]) ? rule[ENUM] : [];
if (rule[ENUM].indexOf(value) === -1) {
errors.push((0, _util.format)(options.messages[ENUM], rule.fullField, rule[ENUM].join(', ')));
}
};
var _default = exports.default = enumerable;

View File

@@ -0,0 +1,9 @@
declare const _default: {
required: import("..").ExecuteRule;
whitespace: import("..").ExecuteRule;
type: import("..").ExecuteRule;
range: import("..").ExecuteRule;
enum: import("..").ExecuteRule;
pattern: import("..").ExecuteRule;
};
export default _default;

View File

@@ -0,0 +1,21 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _enum = _interopRequireDefault(require("./enum"));
var _pattern = _interopRequireDefault(require("./pattern"));
var _range = _interopRequireDefault(require("./range"));
var _required = _interopRequireDefault(require("./required"));
var _type = _interopRequireDefault(require("./type"));
var _whitespace = _interopRequireDefault(require("./whitespace"));
var _default = exports.default = {
required: _required.default,
whitespace: _whitespace.default,
type: _type.default,
range: _range.default,
enum: _enum.default,
pattern: _pattern.default
};

View File

@@ -0,0 +1,3 @@
import type { ExecuteRule } from '../interface';
declare const pattern: ExecuteRule;
export default pattern;

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _util = require("../util");
var pattern = function pattern(rule, value, source, errors, options) {
if (rule.pattern) {
if (rule.pattern instanceof RegExp) {
// if a RegExp instance is passed, reset `lastIndex` in case its `global`
// flag is accidentally set to `true`, which in a validation scenario
// is not necessary and the result might be misleading
rule.pattern.lastIndex = 0;
if (!rule.pattern.test(value)) {
errors.push((0, _util.format)(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
}
} else if (typeof rule.pattern === 'string') {
var _pattern = new RegExp(rule.pattern);
if (!_pattern.test(value)) {
errors.push((0, _util.format)(options.messages.pattern.mismatch, rule.fullField, value, rule.pattern));
}
}
}
};
var _default = exports.default = pattern;

View File

@@ -0,0 +1,3 @@
import type { ExecuteRule } from '../interface';
declare const range: ExecuteRule;
export default range;

View File

@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _util = require("../util");
var range = function range(rule, value, source, errors, options) {
var len = typeof rule.len === 'number';
var min = typeof rule.min === 'number';
var max = typeof rule.max === 'number';
// 正则匹配码点范围从U+010000一直到U+10FFFF的文字补充平面Supplementary Plane
var spRegexp = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
var val = value;
var key = null;
var num = typeof value === 'number';
var str = typeof value === 'string';
var arr = Array.isArray(value);
if (num) {
key = 'number';
} else if (str) {
key = 'string';
} else if (arr) {
key = 'array';
}
// if the value is not of a supported type for range validation
// the validation rule rule should use the
// type property to also test for a particular type
if (!key) {
return false;
}
if (arr) {
val = value.length;
}
if (str) {
// 处理码点大于U+010000的文字length属性不准确的bug如"𠮷𠮷𠮷".length !== 3
val = value.replace(spRegexp, '_').length;
}
if (len) {
if (val !== rule.len) {
errors.push((0, _util.format)(options.messages[key].len, rule.fullField, rule.len));
}
} else if (min && !max && val < rule.min) {
errors.push((0, _util.format)(options.messages[key].min, rule.fullField, rule.min));
} else if (max && !min && val > rule.max) {
errors.push((0, _util.format)(options.messages[key].max, rule.fullField, rule.max));
} else if (min && max && (val < rule.min || val > rule.max)) {
errors.push((0, _util.format)(options.messages[key].range, rule.fullField, rule.min, rule.max));
}
};
var _default = exports.default = range;

View File

@@ -0,0 +1,3 @@
import type { ExecuteRule } from '../interface';
declare const required: ExecuteRule;
export default required;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _util = require("../util");
var required = function required(rule, value, source, errors, options, type) {
if (rule.required && (!source.hasOwnProperty(rule.field) || (0, _util.isEmptyValue)(value, type || rule.type))) {
errors.push((0, _util.format)(options.messages.required, rule.fullField));
}
};
var _default = exports.default = required;

View File

@@ -0,0 +1,3 @@
import type { ExecuteRule } from '../interface';
declare const type: ExecuteRule;
export default type;

View File

@@ -0,0 +1,84 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _util = require("../util");
var _required = _interopRequireDefault(require("./required"));
var _url = _interopRequireDefault(require("./url"));
/* eslint max-len:0 */
var pattern = {
// http://emailregex.com/
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,
// url: new RegExp(
// '^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
// 'i',
// ),
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
};
var types = {
integer: function integer(value) {
return types.number(value) && parseInt(value, 10) === value;
},
float: function float(value) {
return types.number(value) && !types.integer(value);
},
array: function array(value) {
return Array.isArray(value);
},
regexp: function regexp(value) {
if (value instanceof RegExp) {
return true;
}
try {
return !!new RegExp(value);
} catch (e) {
return false;
}
},
date: function date(value) {
return typeof value.getTime === 'function' && typeof value.getMonth === 'function' && typeof value.getYear === 'function' && !isNaN(value.getTime());
},
number: function number(value) {
if (isNaN(value)) {
return false;
}
return typeof value === 'number';
},
object: function object(value) {
return (0, _typeof2.default)(value) === 'object' && !types.array(value);
},
method: function method(value) {
return typeof value === 'function';
},
email: function email(value) {
return typeof value === 'string' && value.length <= 320 && !!value.match(pattern.email);
},
url: function url(value) {
return typeof value === 'string' && value.length <= 2048 && !!value.match((0, _url.default)());
},
hex: function hex(value) {
return typeof value === 'string' && !!value.match(pattern.hex);
}
};
var type = function type(rule, value, source, errors, options) {
if (rule.required && value === undefined) {
(0, _required.default)(rule, value, source, errors, options);
return;
}
var custom = ['integer', 'float', 'array', 'regexp', 'object', 'method', 'email', 'number', 'date', 'url', 'hex'];
var ruleType = rule.type;
if (custom.indexOf(ruleType) > -1) {
if (!types[ruleType](value)) {
errors.push((0, _util.format)(options.messages.types[ruleType], rule.fullField, rule.type));
}
// straight typeof check
} else if (ruleType && (0, _typeof2.default)(value) !== rule.type) {
errors.push((0, _util.format)(options.messages.types[ruleType], rule.fullField, rule.type));
}
};
var _default = exports.default = type;

View File

@@ -0,0 +1,2 @@
declare const _default: () => RegExp;
export default _default;

View File

@@ -0,0 +1,57 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
// https://github.com/kevva/url-regex/blob/master/index.js
var urlReg;
var _default = exports.default = function _default() {
if (urlReg) {
return urlReg;
}
var word = '[a-fA-F\\d:]';
var b = function b(options) {
return options && options.includeBoundaries ? "(?:(?<=\\s|^)(?=".concat(word, ")|(?<=").concat(word, ")(?=\\s|$))") : '';
};
var v4 = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}';
var v6seg = '[a-fA-F\\d]{1,4}';
var v6List = ["(?:".concat(v6seg, ":){7}(?:").concat(v6seg, "|:)"), // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
"(?:".concat(v6seg, ":){6}(?:").concat(v4, "|:").concat(v6seg, "|:)"), // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::
"(?:".concat(v6seg, ":){5}(?::").concat(v4, "|(?::").concat(v6seg, "){1,2}|:)"), // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::
"(?:".concat(v6seg, ":){4}(?:(?::").concat(v6seg, "){0,1}:").concat(v4, "|(?::").concat(v6seg, "){1,3}|:)"), // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::
"(?:".concat(v6seg, ":){3}(?:(?::").concat(v6seg, "){0,2}:").concat(v4, "|(?::").concat(v6seg, "){1,4}|:)"), // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::
"(?:".concat(v6seg, ":){2}(?:(?::").concat(v6seg, "){0,3}:").concat(v4, "|(?::").concat(v6seg, "){1,5}|:)"), // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::
"(?:".concat(v6seg, ":){1}(?:(?::").concat(v6seg, "){0,4}:").concat(v4, "|(?::").concat(v6seg, "){1,6}|:)"), // 1:: 1::3:4:5:6:7:8 1::8 1::
"(?::(?:(?::".concat(v6seg, "){0,5}:").concat(v4, "|(?::").concat(v6seg, "){1,7}|:))") // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::
];
var v6Eth0 = "(?:%[0-9a-zA-Z]{1,})?"; // %eth0 %1
var v6 = "(?:".concat(v6List.join('|'), ")").concat(v6Eth0);
// Pre-compile only the exact regexes because adding a global flag make regexes stateful
var v46Exact = new RegExp("(?:^".concat(v4, "$)|(?:^").concat(v6, "$)"));
var v4exact = new RegExp("^".concat(v4, "$"));
var v6exact = new RegExp("^".concat(v6, "$"));
var ip = function ip(options) {
return options && options.exact ? v46Exact : new RegExp("(?:".concat(b(options)).concat(v4).concat(b(options), ")|(?:").concat(b(options)).concat(v6).concat(b(options), ")"), 'g');
};
ip.v4 = function (options) {
return options && options.exact ? v4exact : new RegExp("".concat(b(options)).concat(v4).concat(b(options)), 'g');
};
ip.v6 = function (options) {
return options && options.exact ? v6exact : new RegExp("".concat(b(options)).concat(v6).concat(b(options)), 'g');
};
var protocol = "(?:(?:[a-z]+:)?//)";
var auth = '(?:\\S+(?::\\S*)?@)?';
var ipv4 = ip.v4().source;
var ipv6 = ip.v6().source;
var host = "(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)";
var domain = "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*";
var tld = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))";
var port = '(?::\\d{2,5})?';
var path = '(?:[/?#][^\\s"]*)?';
var regex = "(?:".concat(protocol, "|www\\.)").concat(auth, "(?:localhost|").concat(ipv4, "|").concat(ipv6, "|").concat(host).concat(domain).concat(tld, ")").concat(port).concat(path);
urlReg = new RegExp("(?:^".concat(regex, "$)"), 'i');
return urlReg;
};

View File

@@ -0,0 +1,14 @@
import type { ExecuteRule } from '../interface';
/**
* Rule for validating whitespace.
*
* @param rule The validation rule.
* @param value The value of the field on the source object.
* @param source The source object being validated.
* @param errors An array of errors that this rule may add
* validation errors to.
* @param options The validation options.
* @param options.messages The validation messages.
*/
declare const whitespace: ExecuteRule;
export default whitespace;

View File

@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _util = require("../util");
/**
* Rule for validating whitespace.
*
* @param rule The validation rule.
* @param value The value of the field on the source object.
* @param source The source object being validated.
* @param errors An array of errors that this rule may add
* validation errors to.
* @param options The validation options.
* @param options.messages The validation messages.
*/
var whitespace = function whitespace(rule, value, source, errors, options) {
if (/^\s+$/.test(value) || value === '') {
errors.push((0, _util.format)(options.messages.whitespace, rule.fullField));
}
};
var _default = exports.default = whitespace;