mm_validator 1.0.0 → 1.0.2

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/tool/jwt/index.js CHANGED
@@ -1,7 +1,109 @@
1
- 'use strict';
1
+ const crypto = require('crypto');
2
+
2
3
  /**
3
- * jwt —— 工具契约适配层
4
- * 业务实现归位于模块 lib/tools/jwt/,本文件只把模块能力暴露给加载器。
5
- * 其它模块可直接 require('mm_validator').tools.jwt 复用。
4
+ * JWT验证器
5
+ * 验证JSON Web Token的有效性,支持签发、校验和解析
6
+ * 使用 HMAC-SHA256 算法进行签名和验证
6
7
  */
7
- module.exports = require('../../lib/tools/jwt');
8
+ async function main(params, ctx, options) {
9
+ const action = params.action;
10
+ const token = params.token;
11
+ const payload = params.payload || {};
12
+ const secret = params.secret;
13
+ const expires_in = params.expires_in || 3600;
14
+
15
+ switch (action) {
16
+ case 'sign': {
17
+ const header = { alg: 'HS256', typ: 'JWT' };
18
+ const now = Math.floor(Date.now() / 1000);
19
+ const jwt_payload = Object.assign({}, payload, { iat: now, exp: now + expires_in });
20
+ const header_str = Buffer.from(JSON.stringify(header)).toString('base64url');
21
+ const payload_str = Buffer.from(JSON.stringify(jwt_payload)).toString('base64url');
22
+ const signing_input = header_str + '.' + payload_str;
23
+ const signature = crypto.createHmac('sha256', secret).update(signing_input).digest('base64url');
24
+ const signed_token = signing_input + '.' + signature;
25
+ ctx.output = {
26
+ valid: true,
27
+ tip: '参数校验通过',
28
+ errors: [],
29
+ payload: { token: signed_token }
30
+ };
31
+ return ctx.output;
32
+ }
33
+ case 'verify': {
34
+ const parts = (token || '').split('.');
35
+ if (parts.length !== 3) {
36
+ ctx.output = {
37
+ valid: false,
38
+ tip: '1个参数校验失败: Token格式无效',
39
+ errors: ['Token格式无效'],
40
+ payload: null
41
+ };
42
+ return ctx.output;
43
+ }
44
+ var expected_sig = crypto
45
+ .createHmac('sha256', secret)
46
+ .update(parts[0] + '.' + parts[1])
47
+ .digest('base64url');
48
+ if (parts[2] !== expected_sig) {
49
+ ctx.output = {
50
+ valid: false,
51
+ tip: '1个参数校验失败: 签名验证失败',
52
+ errors: ['签名验证失败'],
53
+ payload: null
54
+ };
55
+ return ctx.output;
56
+ }
57
+ const decoded_payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString());
58
+ const now = Math.floor(Date.now() / 1000);
59
+ if (decoded_payload.exp && decoded_payload.exp < now) {
60
+ ctx.output = {
61
+ valid: false,
62
+ tip: '1个参数校验失败: Token已过期',
63
+ errors: ['Token已过期'],
64
+ payload: null
65
+ };
66
+ return ctx.output;
67
+ }
68
+ ctx.output = {
69
+ valid: true,
70
+ tip: '参数校验通过',
71
+ errors: [],
72
+ payload: decoded_payload
73
+ };
74
+ return ctx.output;
75
+ }
76
+ case 'decode': {
77
+ const parts = (token || '').split('.');
78
+ if (parts.length !== 3) {
79
+ ctx.output = {
80
+ valid: false,
81
+ tip: '1个参数校验失败: Token格式无效',
82
+ errors: ['Token格式无效'],
83
+ payload: null
84
+ };
85
+ return ctx.output;
86
+ }
87
+ const decoded_header = JSON.parse(Buffer.from(parts[0], 'base64url').toString());
88
+ const decoded_payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString());
89
+ ctx.output = {
90
+ valid: true,
91
+ tip: '参数校验通过',
92
+ errors: [],
93
+ payload: { header: decoded_header, payload: decoded_payload }
94
+ };
95
+ return ctx.output;
96
+ }
97
+ default: {
98
+ ctx.output = {
99
+ valid: false,
100
+ tip: '1个参数校验失败: 不支持的操作类型: ' + action,
101
+ errors: ['不支持的操作类型: ' + action],
102
+ payload: null
103
+ };
104
+ return ctx.output;
105
+ }
106
+ }
107
+ }
108
+
109
+ module.exports = { main };
@@ -1,7 +1,61 @@
1
- 'use strict';
2
1
  /**
3
- * length —— 工具契约适配层
4
- * 业务实现归位于模块 lib/tools/length/,本文件只把模块能力暴露给加载器。
5
- * 其它模块可直接 require('mm_validator').tools.length 复用。
2
+ * 长度验证器
3
+ * 验证字符串或数组长度是否在指定范围内
4
+ * 支持单规则和多规则(rules 数组)两种模式
6
5
  */
7
- module.exports = require('../../lib/tools/length');
6
+
7
+ async function main(params, ctx, options) {
8
+ var errors = [];
9
+
10
+ // 多规则模式: { rules: [{ field, value, min, max }, ...] }
11
+ if (params.rules && Array.isArray(params.rules)) {
12
+ for (var i = 0; i < params.rules.length; i++) {
13
+ var rule = params.rules[i];
14
+ var val = rule.value;
15
+ var len = 0;
16
+
17
+ if (typeof val === 'string' || Array.isArray(val)) {
18
+ len = val.length;
19
+ } else if (val !== null && val !== undefined) {
20
+ errors.push(rule.field + ' 必须是字符串或数组');
21
+ continue;
22
+ }
23
+
24
+ if (rule.min !== undefined && len < rule.min) {
25
+ errors.push(rule.field + ' 长度不能小于 ' + rule.min);
26
+ }
27
+ if (rule.max !== undefined && len > rule.max) {
28
+ errors.push(rule.field + ' 长度不能大于 ' + rule.max);
29
+ }
30
+ }
31
+ } else {
32
+ // 单规则模式(向后兼容): { field, value, min, max }
33
+ var value = params.value;
34
+ var min = params.min;
35
+ var max = params.max;
36
+ var len = 0;
37
+
38
+ if (typeof value === 'string' || Array.isArray(value)) {
39
+ len = value.length;
40
+ } else if (value !== null && value !== undefined) {
41
+ errors.push(params.field + ' 必须是字符串或数组');
42
+ var tip = '1个参数校验失败: ' + errors.join('; ');
43
+ ctx.output = { valid: false, tip: tip, errors: errors };
44
+ return ctx.output;
45
+ }
46
+
47
+ if (min !== undefined && len < min) {
48
+ errors.push(params.field + ' 长度不能小于 ' + min);
49
+ }
50
+ if (max !== undefined && len > max) {
51
+ errors.push(params.field + ' 长度不能大于 ' + max);
52
+ }
53
+ }
54
+
55
+ var valid = errors.length === 0;
56
+ var tip = valid ? '参数校验通过' : errors.length + '个参数校验失败: ' + errors.join('; ');
57
+ ctx.output = { valid: valid, tip: tip, errors: errors };
58
+ return ctx.output;
59
+ }
60
+
61
+ module.exports = { main };
@@ -1,7 +1,170 @@
1
- 'use strict';
2
1
  /**
3
- * oauth —— 工具契约适配层
4
- * 业务实现归位于模块 lib/tools/oauth/,本文件只把模块能力暴露给加载器。
5
- * 其它模块可直接 require('mm_validator').tools.oauth 复用。
2
+ * OAuth验证器
3
+ * 验证 OAuth 2.0 令牌格式和有效期
4
+ * 支持 JWT 格式的 access_token 解码校验、刷新和吊销
6
5
  */
7
- module.exports = require('../../lib/tools/oauth');
6
+
7
+ function decodeJwt(token) {
8
+ var parts = token.split('.');
9
+ if (parts.length !== 3) return null;
10
+ try {
11
+ var header = JSON.parse(Buffer.from(parts[0], 'base64').toString('utf-8'));
12
+ var payload = JSON.parse(Buffer.from(parts[1], 'base64').toString('utf-8'));
13
+ return { header: header, payload: payload };
14
+ } catch (_e) {
15
+ return null;
16
+ }
17
+ }
18
+
19
+ function encodeJwt(payload) {
20
+ var header = { alg: 'none', typ: 'JWT' };
21
+ var header_b64 = Buffer.from(JSON.stringify(header))
22
+ .toString('base64')
23
+ .replace(/=/g, '')
24
+ .replace(/\+/g, '-')
25
+ .replace(/\//g, '_');
26
+ var payload_b64 = Buffer.from(JSON.stringify(payload))
27
+ .toString('base64')
28
+ .replace(/=/g, '')
29
+ .replace(/\+/g, '-')
30
+ .replace(/\//g, '_');
31
+ return header_b64 + '.' + payload_b64 + '.';
32
+ }
33
+
34
+ function isTokenRevoked(token) {
35
+ if (!global.__revoked_tokens) return false;
36
+ var token_id = String(token).slice(0, 20);
37
+ return !!global.__revoked_tokens[token_id];
38
+ }
39
+
40
+ async function main(params, ctx, options) {
41
+ var action = params.action || 'validate';
42
+ var access_token = params.access_token || (ctx.meta && ctx.meta.token) || '';
43
+ var refresh_token = params.refresh_token || '';
44
+ var scope = params.scope || '';
45
+ var expires_in = params.expires_in || 3600;
46
+
47
+ switch (action) {
48
+ case 'validate': {
49
+ if (!access_token) {
50
+ ctx.output = {
51
+ valid: false,
52
+ tip: '1个参数校验失败: 缺少access_token',
53
+ errors: ['缺少access_token']
54
+ };
55
+ return ctx.output;
56
+ }
57
+
58
+ // 检查令牌是否已被吊销
59
+ if (isTokenRevoked(access_token)) {
60
+ ctx.output = {
61
+ valid: false,
62
+ tip: '1个参数校验失败: 令牌已被吊销',
63
+ errors: ['令牌已被吊销']
64
+ };
65
+ return ctx.output;
66
+ }
67
+
68
+ // JWT 格式校验:检查是否为三段式 base64 token
69
+ var parts = access_token.split('.');
70
+ var is_jwt = parts.length === 3;
71
+ var expired = false;
72
+ var payload = {};
73
+
74
+ if (is_jwt) {
75
+ try {
76
+ var payload_str = Buffer.from(parts[1], 'base64').toString('utf-8');
77
+ payload = JSON.parse(payload_str);
78
+ // 检查过期时间
79
+ if (payload.exp && payload.exp * 1000 < Date.now()) {
80
+ expired = true;
81
+ }
82
+ } catch (_e) {
83
+ // payload 解析失败,视为非标准 JWT
84
+ }
85
+ }
86
+
87
+ var valid = !expired;
88
+ var tip = valid ? '参数校验通过' : '1个参数校验失败: 令牌已过期';
89
+ ctx.output = {
90
+ valid: valid,
91
+ tip: tip,
92
+ errors: expired ? ['令牌已过期'] : []
93
+ };
94
+ return ctx.output;
95
+ }
96
+ case 'decode': {
97
+ if (!access_token) {
98
+ ctx.output = {
99
+ valid: false,
100
+ tip: '1个参数校验失败: 缺少access_token',
101
+ errors: ['缺少access_token']
102
+ };
103
+ return ctx.output;
104
+ }
105
+ var decoded = decodeJwt(access_token);
106
+ if (decoded) {
107
+ ctx.output = { valid: true, tip: '参数校验通过', errors: [] };
108
+ return ctx.output;
109
+ }
110
+ ctx.output = {
111
+ valid: false,
112
+ tip: '1个参数校验失败: 非JWT格式令牌',
113
+ errors: ['非JWT格式令牌']
114
+ };
115
+ return ctx.output;
116
+ }
117
+ case 'refresh': {
118
+ if (!refresh_token) {
119
+ ctx.output = {
120
+ valid: false,
121
+ tip: '1个参数校验失败: 缺少refresh_token',
122
+ errors: ['缺少refresh_token']
123
+ };
124
+ return ctx.output;
125
+ }
126
+
127
+ // 解码 refresh_token 提取 payload
128
+ var rt_decoded = decodeJwt(refresh_token);
129
+ var rt_payload = rt_decoded ? rt_decoded.payload : {};
130
+
131
+ // 构建新 access_token 的 payload
132
+ var now_sec = Math.floor(Date.now() / 1000);
133
+ var new_payload = {
134
+ sub: rt_payload.sub || '',
135
+ scope: rt_payload.scope || '',
136
+ iat: now_sec,
137
+ exp: now_sec + expires_in
138
+ };
139
+
140
+ encodeJwt(new_payload);
141
+
142
+ ctx.output = { valid: true, tip: '参数校验通过', errors: [] };
143
+ return ctx.output;
144
+ }
145
+ case 'revoke': {
146
+ // 初始化吊销令牌存储
147
+ if (!global.__revoked_tokens) {
148
+ global.__revoked_tokens = {};
149
+ }
150
+
151
+ var token_id = String(access_token).slice(0, 20);
152
+ if (token_id) {
153
+ global.__revoked_tokens[token_id] = Date.now();
154
+ }
155
+
156
+ ctx.output = { valid: true, tip: '参数校验通过', errors: [] };
157
+ return ctx.output;
158
+ }
159
+ default: {
160
+ ctx.output = {
161
+ valid: false,
162
+ tip: '1个参数校验失败: 不支持的操作类型: ' + action,
163
+ errors: ['不支持的操作类型: ' + action]
164
+ };
165
+ return ctx.output;
166
+ }
167
+ }
168
+ }
169
+
170
+ module.exports = { main };
@@ -1,7 +1,99 @@
1
- 'use strict';
2
1
  /**
3
- * params —— 工具契约适配层
4
- * 业务实现归位于模块 lib/tools/params/,本文件只把模块能力暴露给加载器。
5
- * 其它模块可直接 require('mm_validator').tools.params 复用。
2
+ * 参数验证器
3
+ * 统一验证所有字段的规则,支持 required/type/min/max/min_length/max_length/pattern/enum
4
+ * 入参: { input: {字段名: 值}, rules: {字段名: {规则}} }
6
5
  */
7
- module.exports = require('../../lib/tools/params');
6
+
7
+ async function main(params, ctx, options) {
8
+ var input = params.input || {};
9
+ var rules = params.rules || {};
10
+ var errors = {};
11
+ var fields = {};
12
+
13
+ for (var field in rules) {
14
+ var rule = rules[field];
15
+ var value = input[field];
16
+ var field_errors = [];
17
+
18
+ // required - 必填检查
19
+ if (rule.required) {
20
+ if (value === null || value === undefined || value === '') {
21
+ field_errors.push(field + ' 为必填项');
22
+ }
23
+ }
24
+
25
+ // 如果值为空且非必填,跳过后续检查
26
+ if (value === null || value === undefined || value === '') {
27
+ if (field_errors.length > 0) {
28
+ errors[field] = field_errors;
29
+ fields[field] = { valid: false, errors: field_errors };
30
+ } else {
31
+ fields[field] = { valid: true, errors: [] };
32
+ }
33
+ continue;
34
+ }
35
+
36
+ // type - 类型检查
37
+ if (rule.type) {
38
+ var actual_type = Array.isArray(value) ? 'array' : typeof value;
39
+ if (actual_type !== rule.type) {
40
+ field_errors.push(field + ' 类型应为 ' + rule.type + ',实际为 ' + actual_type);
41
+ }
42
+ }
43
+
44
+ // min / max - 数值范围
45
+ if (rule.min !== undefined && typeof value === 'number' && value < rule.min) {
46
+ field_errors.push(field + ' 不能小于 ' + rule.min);
47
+ }
48
+ if (rule.max !== undefined && typeof value === 'number' && value > rule.max) {
49
+ field_errors.push(field + ' 不能大于 ' + rule.max);
50
+ }
51
+
52
+ // min_length / max_length - 长度检查
53
+ var len = 0;
54
+ if (typeof value === 'string' || Array.isArray(value)) {
55
+ len = value.length;
56
+ }
57
+ if (rule.min_length !== undefined && len < rule.min_length) {
58
+ field_errors.push(field + ' 长度不能小于 ' + rule.min_length);
59
+ }
60
+ if (rule.max_length !== undefined && len > rule.max_length) {
61
+ field_errors.push(field + ' 长度不能大于 ' + rule.max_length);
62
+ }
63
+
64
+ // pattern - 正则匹配
65
+ if (rule.pattern && typeof value === 'string') {
66
+ var regex;
67
+ try {
68
+ regex = new RegExp(rule.pattern);
69
+ } catch (e) {
70
+ field_errors.push(field + ' 正则格式错误: ' + rule.pattern);
71
+ }
72
+ if (regex && !regex.test(value)) {
73
+ field_errors.push(field + ' 格式不合法');
74
+ }
75
+ }
76
+
77
+ // enum - 枚举检查
78
+ if (rule.enum && Array.isArray(rule.enum)) {
79
+ if (rule.enum.indexOf(value) === -1) {
80
+ field_errors.push(field + ' 值不在允许范围内: ' + rule.enum.join(', '));
81
+ }
82
+ }
83
+
84
+ if (field_errors.length > 0) {
85
+ errors[field] = field_errors;
86
+ fields[field] = { valid: false, errors: field_errors };
87
+ } else {
88
+ fields[field] = { valid: true, errors: [] };
89
+ }
90
+ }
91
+
92
+ var error_count = Object.keys(errors).length;
93
+ var valid = error_count === 0;
94
+ var tip = valid ? '参数校验通过' : error_count + '个参数校验失败: ' + JSON.stringify(errors);
95
+ ctx.output = { valid: valid, tip: tip, errors: errors, fields: fields };
96
+ return ctx.output;
97
+ }
98
+
99
+ module.exports = { main };
@@ -1,7 +1,58 @@
1
- 'use strict';
2
1
  /**
3
- * pattern —— 工具契约适配层
4
- * 业务实现归位于模块 lib/tools/pattern/,本文件只把模块能力暴露给加载器。
5
- * 其它模块可直接 require('mm_validator').tools.pattern 复用。
2
+ * 正则验证器
3
+ * 验证字符串是否匹配指定正则表达式
4
+ * 支持单规则和多规则(rules 数组)两种模式
6
5
  */
7
- module.exports = require('../../lib/tools/pattern');
6
+
7
+ async function main(params, ctx, options) {
8
+ var errors = [];
9
+ var pattern_count = 0;
10
+
11
+ // 多规则模式: { rules: [{ field, value, pattern }, ...] }
12
+ if (params.rules && Array.isArray(params.rules)) {
13
+ pattern_count = params.rules.length;
14
+ for (var i = 0; i < params.rules.length; i++) {
15
+ var rule = params.rules[i];
16
+ if (typeof rule.value !== 'string') {
17
+ errors.push(rule.field + ' 必须是字符串');
18
+ continue;
19
+ }
20
+ var regex;
21
+ try {
22
+ regex = new RegExp(rule.pattern);
23
+ } catch (e) {
24
+ errors.push('正则表达式格式错误: ' + rule.pattern);
25
+ continue;
26
+ }
27
+ if (!regex.test(rule.value)) {
28
+ errors.push(rule.field + ' 格式不匹配');
29
+ }
30
+ }
31
+ } else {
32
+ // 单规则模式(向后兼容): { field, value, pattern }
33
+ pattern_count = 1;
34
+ var value = params.value;
35
+ var pattern = params.pattern;
36
+
37
+ if (typeof value !== 'string') {
38
+ errors.push(params.field + ' 必须是字符串');
39
+ } else {
40
+ var regex;
41
+ try {
42
+ regex = new RegExp(pattern);
43
+ } catch (e) {
44
+ errors.push('正则表达式格式错误: ' + pattern);
45
+ }
46
+ if (regex && !regex.test(value)) {
47
+ errors.push(params.field + ' 不匹配正则: ' + pattern);
48
+ }
49
+ }
50
+ }
51
+
52
+ var valid = errors.length === 0;
53
+ var tip = valid ? '参数校验通过' : errors.length + '个参数校验失败: ' + errors.join('; ');
54
+ ctx.output = { valid: valid, tip: tip, errors: errors, pattern_count: pattern_count };
55
+ return ctx.output;
56
+ }
57
+
58
+ module.exports = { main };
@@ -1,7 +1,112 @@
1
- 'use strict';
2
1
  /**
3
- * range —— 工具契约适配层
4
- * 业务实现归位于模块 lib/tools/range/,本文件只把模块能力暴露给加载器。
5
- * 其它模块可直接 require('mm_validator').tools.range 复用。
2
+ * 范围验证器
3
+ * 验证数值是否在指定范围内,支持多种比较模式:
4
+ * between / not_between / > / >= / < / <= / = / != / in / not_in
5
+ * 支持单规则和多规则(rules 数组)两种模式
6
6
  */
7
- module.exports = require('../../lib/tools/range');
7
+ async function main(params, ctx, options) {
8
+ var errors = [];
9
+ var rule_list;
10
+
11
+ if (params.rules && Array.isArray(params.rules)) {
12
+ rule_list = params.rules;
13
+ } else {
14
+ rule_list = [params];
15
+ }
16
+
17
+ for (var i = 0; i < rule_list.length; i++) {
18
+ var rule = rule_list[i];
19
+ _validateRule(rule, errors);
20
+ }
21
+
22
+ var valid = errors.length === 0;
23
+ var tip = valid ? '参数校验通过' : errors.length + '个参数校验失败: ' + errors.join('; ');
24
+ ctx.output = { valid: valid, tip: tip, errors: errors };
25
+ return ctx.output;
26
+ }
27
+
28
+ function _validateRule(rule, errors) {
29
+ var value = rule.value;
30
+ var min = rule.min;
31
+ var max = rule.max;
32
+ var mode = rule.mode || 'between';
33
+ var inclusive_min = rule.inclusive_min !== false;
34
+ var inclusive_max = rule.inclusive_max !== false;
35
+ var label = rule.field || rule.label || '值';
36
+
37
+ switch (mode) {
38
+ case 'between':
39
+ if (min !== undefined && value !== undefined) {
40
+ if (inclusive_min ? value < min : value <= min) {
41
+ errors.push(label + ' 不能小于' + (inclusive_min ? '' : '等于') + ' ' + min);
42
+ }
43
+ }
44
+ if (max !== undefined && value !== undefined) {
45
+ if (inclusive_max ? value > max : value >= max) {
46
+ errors.push(label + ' 不能大于' + (inclusive_max ? '' : '等于') + ' ' + max);
47
+ }
48
+ }
49
+ break;
50
+ case 'not_between':
51
+ if (min !== undefined && max !== undefined && value !== undefined) {
52
+ if (value >= min && value <= max) {
53
+ errors.push(label + ' 不能在 ' + min + ' ~ ' + max + ' 之间');
54
+ }
55
+ }
56
+ break;
57
+ case '>':
58
+ if (min !== undefined && value !== undefined && value <= min) {
59
+ errors.push(label + ' 必须大于 ' + min);
60
+ }
61
+ break;
62
+ case '>=':
63
+ if (min !== undefined && value !== undefined && value < min) {
64
+ errors.push(label + ' 必须大于等于 ' + min);
65
+ }
66
+ break;
67
+ case '<':
68
+ if (max !== undefined && value !== undefined && value >= max) {
69
+ errors.push(label + ' 必须小于 ' + max);
70
+ }
71
+ break;
72
+ case '<=':
73
+ if (max !== undefined && value !== undefined && value > max) {
74
+ errors.push(label + ' 必须小于等于 ' + max);
75
+ }
76
+ break;
77
+ case '=':
78
+ if (min !== undefined && value !== undefined && value !== min) {
79
+ errors.push(label + ' 必须等于 ' + min);
80
+ }
81
+ break;
82
+ case '!=':
83
+ if (min !== undefined && value !== undefined && value === min) {
84
+ errors.push(label + ' 不能等于 ' + min);
85
+ }
86
+ break;
87
+ case 'in':
88
+ if (rule.values !== undefined && Array.isArray(rule.values)) {
89
+ if (rule.values.indexOf(value) === -1) {
90
+ errors.push(label + ' 必须在 [' + rule.values.join(', ') + '] 之中');
91
+ }
92
+ }
93
+ break;
94
+ case 'not_in':
95
+ if (rule.values !== undefined && Array.isArray(rule.values)) {
96
+ if (rule.values.indexOf(value) !== -1) {
97
+ errors.push(label + ' 不能在 [' + rule.values.join(', ') + '] 之中');
98
+ }
99
+ }
100
+ break;
101
+ default:
102
+ if (min !== undefined && value !== undefined && value < min) {
103
+ errors.push(label + ' 不能小于 ' + min);
104
+ }
105
+ if (max !== undefined && value !== undefined && value > max) {
106
+ errors.push(label + ' 不能大于 ' + max);
107
+ }
108
+ break;
109
+ }
110
+ }
111
+
112
+ module.exports = { main };