mm_expand 2.1.2 → 2.1.3
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/index.js +9 -0
- package/lib/base.js +45 -27
- package/lib/errors.js +160 -0
- package/lib/event.js +67 -45
- package/lib/eventer.js +39 -13
- package/lib/file.js +29 -24
- package/lib/lang.js +52 -68
- package/lib/logger.js +35 -18
- package/lib/req.js +268 -0
- package/lib/ret.js +338 -0
- package/lib/timer.js +1 -4
- package/lib/validator.js +35 -46
- package/package.json +3 -2
package/lib/validator.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require('./
|
|
1
|
+
const { Base } = require('./base.js');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 验证器
|
|
5
5
|
*/
|
|
6
|
-
class Validator {
|
|
6
|
+
class Validator extends Base {
|
|
7
7
|
/**
|
|
8
8
|
* 验证格式
|
|
9
9
|
* @type {object}
|
|
@@ -72,15 +72,15 @@ class Validator {
|
|
|
72
72
|
*/
|
|
73
73
|
static _getBasicText() {
|
|
74
74
|
return {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
name: /^[a-z]+(_[a-z]+)*[0-9]*$/,
|
|
76
|
+
username: /^[a-z0-9A-Z_]+$/,
|
|
77
|
+
password: /^[a-z0-9A-Z]+$/,
|
|
78
|
+
en: /^[a-zA-Z]+$/,
|
|
79
|
+
ch: /^[\u4e00-\u9fa5]+$/,
|
|
80
|
+
chs: /^[\u4e00-\u9fa5]+$/,
|
|
81
|
+
chinese: /^[\u4e00-\u9fa5]+$/,
|
|
82
|
+
filename: /^[^\\/:*?"<>|]+$/,
|
|
83
|
+
licenseplate: new RegExp('^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]' +
|
|
84
84
|
'[A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$')
|
|
85
85
|
};
|
|
86
86
|
}
|
|
@@ -109,13 +109,13 @@ class Validator {
|
|
|
109
109
|
*/
|
|
110
110
|
static _getEcommerceFormats() {
|
|
111
111
|
return {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
sku: /^[A-Z0-9]{6,20}$/, // 商品SKU编码
|
|
113
|
+
order_no: /^[A-Z0-9]{10,20}$/, // 订单号
|
|
114
|
+
tracking_no: /^[A-Z0-9]{10,30}$/, // 物流单号
|
|
115
|
+
coupon_code: /^[A-Z0-9]{8,16}$/, // 优惠券码
|
|
116
|
+
product_code: /^[A-Z0-9]{4,12}$/, // 商品编码
|
|
117
|
+
barcode: /^[0-9]{8,13}$/, // 商品条形码
|
|
118
|
+
inventory_code: /^[A-Z0-9]{6,15}$/ // 库存编码
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -125,14 +125,14 @@ class Validator {
|
|
|
125
125
|
*/
|
|
126
126
|
static _getFinancialFormats() {
|
|
127
127
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
bank_account: /^[0-9]{16,19}$/, // 银行账号
|
|
129
|
+
credit_card: /^[0-9]{13,19}$/, // 信用卡号
|
|
130
|
+
swift_code: /^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/, // SWIFT代码
|
|
131
|
+
iban: /^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/, // IBAN账号
|
|
132
|
+
tax_id: /^[A-Z0-9]{10,20}$/, // 纳税人识别号
|
|
133
|
+
stock_code: /^[0-9]{6}$/, // 股票代码
|
|
134
|
+
fund_code: /^[0-9]{6}$/, // 基金代码
|
|
135
|
+
insurance_policy: /^[A-Z0-9]{10,20}$/ // 保险单号
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
|
|
@@ -173,16 +173,16 @@ class Validator {
|
|
|
173
173
|
*/
|
|
174
174
|
static _getGeoFormats() {
|
|
175
175
|
return {
|
|
176
|
-
|
|
176
|
+
coordinate: new RegExp('^-?(?:[0-8]?[0-9]|90)(?:\\.\\d{1,6})?,' +
|
|
177
177
|
'-?(?:1[0-7][0-9]|180|[0-9]?[0-9])' +
|
|
178
178
|
'(?:\\.\\d{1,6})?$'), // 经纬度坐标(纬度-90~90,经度-180~180)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
address: /^[\u4e00-\u9fa5A-Za-z0-9\s\-#,./]{5,100}$/, // 详细地址
|
|
180
|
+
postal_code: /^[0-9]{6}$/, // 邮政编码
|
|
181
|
+
area_code: /^0[0-9]{2,3}$/, // 区号
|
|
182
|
+
country_code: /^[A-Z]{2,3}$/, // 国家代码
|
|
183
|
+
province_code: /^[0-9]{2}$/, // 省份代码
|
|
184
|
+
city_code: /^[0-9]{4}$/, // 城市代码
|
|
185
|
+
district_code: /^[0-9]{6}$/ // 区县代码
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
|
|
@@ -191,14 +191,11 @@ class Validator {
|
|
|
191
191
|
* @param {object} config 配置项
|
|
192
192
|
*/
|
|
193
193
|
constructor(config) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
};
|
|
194
|
+
super(config);
|
|
197
195
|
/**
|
|
198
196
|
* 验证格式
|
|
199
197
|
*/
|
|
200
198
|
this._format = Validator.format;
|
|
201
|
-
this.setConfig(config);
|
|
202
199
|
}
|
|
203
200
|
}
|
|
204
201
|
|
|
@@ -211,14 +208,6 @@ Validator.prototype.init = function () {
|
|
|
211
208
|
Object.assign(this._format, Validator.format);
|
|
212
209
|
};
|
|
213
210
|
|
|
214
|
-
/**
|
|
215
|
-
* 设置配置项
|
|
216
|
-
* @param {object} config 配置项
|
|
217
|
-
*/
|
|
218
|
-
Validator.prototype.setConfig = function (config) {
|
|
219
|
-
Object.assign(this.config, config || {});
|
|
220
|
-
};
|
|
221
|
-
|
|
222
211
|
/**
|
|
223
212
|
* 验证字符串
|
|
224
213
|
* @param {string} str 字符串
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Super Meimei Prototype Function Extension Module - Enhanced operations for string, array, object, date manipulation with error prevention and simplified business logic.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"lint": "eslint lib/**/*.js",
|
|
9
9
|
"lint:fix": "eslint lib/**/*.js --fix",
|
|
10
10
|
"typecheck": "echo 'JavaScript项目无需类型检查'",
|
|
11
|
-
"check": "npm run lint && npm run test"
|
|
11
|
+
"check": "npm run lint && npm run test",
|
|
12
|
+
"dev": "nodemon dev.js"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|