mm_expand 2.3.4 → 2.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/array.js +36 -36
- package/lib/base.js +15 -15
- package/lib/date.js +9 -8
- package/lib/errors.js +99 -99
- package/lib/event.js +45 -45
- package/lib/eventer.js +166 -165
- package/lib/file.js +126 -14
- package/lib/global.js +51 -53
- package/lib/lang.js +10 -10
- package/lib/logger.js +2 -2
- package/lib/number.js +10 -10
- package/lib/object.js +72 -75
- package/lib/req.js +42 -42
- package/lib/ret.js +248 -249
- package/lib/string.js +87 -93
- package/lib/timer.js +15 -15
- package/lib/validator.js +11 -11
- package/package.json +6 -6
package/lib/validator.js
CHANGED
|
@@ -11,8 +11,8 @@ class Validator extends Base {
|
|
|
11
11
|
static get format() {
|
|
12
12
|
return Object.assign(
|
|
13
13
|
Validator._getBasicFormats(),
|
|
14
|
-
Validator.
|
|
15
|
-
Validator.
|
|
14
|
+
Validator._getEcomFormats(),
|
|
15
|
+
Validator._getFinaFormats(),
|
|
16
16
|
Validator._getGeoFormats()
|
|
17
17
|
);
|
|
18
18
|
}
|
|
@@ -27,7 +27,7 @@ class Validator extends Base {
|
|
|
27
27
|
Validator._getBasicDateTime(),
|
|
28
28
|
Validator._getBasicText(),
|
|
29
29
|
Validator._getBasicNetwork(),
|
|
30
|
-
Validator.
|
|
30
|
+
Validator._getBasic(),
|
|
31
31
|
Validator._getBasicTech()
|
|
32
32
|
);
|
|
33
33
|
}
|
|
@@ -107,7 +107,7 @@ class Validator extends Base {
|
|
|
107
107
|
* 获取电商相关验证格式
|
|
108
108
|
* @returns {object} 电商验证格式
|
|
109
109
|
*/
|
|
110
|
-
static
|
|
110
|
+
static _getEcomFormats() {
|
|
111
111
|
return {
|
|
112
112
|
sku: /^[A-Z0-9]{6,20}$/, // 商品SKU编码
|
|
113
113
|
order_no: /^[A-Z0-9]{10,20}$/, // 订单号
|
|
@@ -123,7 +123,7 @@ class Validator extends Base {
|
|
|
123
123
|
* 获取金融相关验证格式
|
|
124
124
|
* @returns {object} 金融验证格式
|
|
125
125
|
*/
|
|
126
|
-
static
|
|
126
|
+
static _getFinaFormats() {
|
|
127
127
|
return {
|
|
128
128
|
bank_account: /^[0-9]{16,19}$/, // 银行账号
|
|
129
129
|
credit_card: /^[0-9]{13,19}$/, // 信用卡号
|
|
@@ -140,7 +140,7 @@ class Validator extends Base {
|
|
|
140
140
|
* 获取基础数据格式
|
|
141
141
|
* @returns {object} 数据格式
|
|
142
142
|
*/
|
|
143
|
-
static
|
|
143
|
+
static _getBasic() {
|
|
144
144
|
return {
|
|
145
145
|
number: /^[1-9]+[0-9]*(\.[0-9]+|[0-9]*)|0\.[0-9]+|0$/,
|
|
146
146
|
num: /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/,
|
|
@@ -201,7 +201,7 @@ class Validator extends Base {
|
|
|
201
201
|
|
|
202
202
|
/**
|
|
203
203
|
* 初始化验证规则
|
|
204
|
-
*
|
|
204
|
+
* 初始化验证规则,避免污染
|
|
205
205
|
*/
|
|
206
206
|
Validator.prototype.reset = function () {
|
|
207
207
|
// 初始化验证规则,避免污染
|
|
@@ -1231,7 +1231,7 @@ Validator.prototype.isDistrictCode = function (val) {
|
|
|
1231
1231
|
* @param {string} data_type 数据类型
|
|
1232
1232
|
* @returns {object} 类型信息对象
|
|
1233
1233
|
*/
|
|
1234
|
-
Validator.prototype.
|
|
1234
|
+
Validator.prototype.getTypeInfo = function (data_type) {
|
|
1235
1235
|
const type_map = {
|
|
1236
1236
|
'string': ['char', 'varchar', 'text'],
|
|
1237
1237
|
'number': ['bigint', 'int', 'double', 'float', 'mediumint', 'smallint', 'tinyint'],
|
|
@@ -1291,7 +1291,7 @@ Validator.prototype.createRuleObject = function (options) {
|
|
|
1291
1291
|
*/
|
|
1292
1292
|
Validator.prototype.newRule = function (data_type = 'text', min = 0,
|
|
1293
1293
|
max = Number.MAX_SAFE_INTEGER) {
|
|
1294
|
-
const { type, check_type } = this.
|
|
1294
|
+
const { type, check_type } = this.getTypeInfo(data_type);
|
|
1295
1295
|
return this.createRuleObject({ type, check_type, min, max });
|
|
1296
1296
|
};
|
|
1297
1297
|
|
|
@@ -1423,7 +1423,7 @@ Validator.prototype.checkSame = function (val, rule, obj) {
|
|
|
1423
1423
|
* @param {object} obj 数据对象
|
|
1424
1424
|
* @returns {string} 错误信息或空字符串
|
|
1425
1425
|
*/
|
|
1426
|
-
Validator.prototype.
|
|
1426
|
+
Validator.prototype.checkDiff = function (val, rule, obj) {
|
|
1427
1427
|
if (rule.different) {
|
|
1428
1428
|
let target_val = obj[rule.different];
|
|
1429
1429
|
if (val === target_val) {
|
|
@@ -1505,7 +1505,7 @@ Validator.prototype.checkVal = function (obj, key, rule) {
|
|
|
1505
1505
|
tip = this.checkSame(val, rule, obj);
|
|
1506
1506
|
if (tip) return tip;
|
|
1507
1507
|
|
|
1508
|
-
tip = this.
|
|
1508
|
+
tip = this.checkDiff(val, rule, obj);
|
|
1509
1509
|
if (tip) return tip;
|
|
1510
1510
|
|
|
1511
1511
|
return '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.5",
|
|
4
4
|
"description": "超级美眉原型函数扩展模块 - 增强的字符串、数组、对象、日期操作,具备错误预防功能并简化业务逻辑",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"homepage": "https://gitee.com/qiuwenwu91/mm_expand#readme",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"colors": "^1.4.0",
|
|
37
|
-
"fast-xml-parser": "^5.
|
|
37
|
+
"fast-xml-parser": "^5.9.3",
|
|
38
38
|
"json5": "^2.2.3",
|
|
39
39
|
"ncp": "^2.0.0",
|
|
40
40
|
"pinyinlite": "^1.2.1",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"test": "test"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"eslint": "^10.
|
|
49
|
-
"eslint-plugin-jsdoc": "^
|
|
50
|
-
"mm_eslint": "^1.7.
|
|
48
|
+
"eslint": "^10.6.0",
|
|
49
|
+
"eslint-plugin-jsdoc": "^63.0.9",
|
|
50
|
+
"mm_eslint": "^1.7.5"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=14.0.0"
|
|
@@ -62,4 +62,4 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
}
|
|
65
|
-
}
|
|
65
|
+
}
|