mm_expand 2.0.0 → 2.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/lib/eventer.js CHANGED
@@ -4,19 +4,23 @@ require('./global.js');
4
4
  * 事件类 - 增强版EventBus实现
5
5
  */
6
6
  class Eventer {
7
+ static config = {
8
+ max_listeners: 10, // 最大监听器数量
9
+ default_namespace: 'default', // 默认命名空间
10
+ chain_enabled: true, // 是否启用链式触发
11
+ auto_clean: true, // 是否自动清理空的事件列表
12
+ error_handler: null, // 全局错误处理函数
13
+ pause_enabled: true, // 是否启用暂停功能
14
+ };
7
15
  /**
8
- * 构造函数
9
- * @param {object} config 配置参数
10
- */
16
+ * 构造函数
17
+ * @param {object} config 配置参数
18
+ */
11
19
  constructor(config) {
12
- this.config = Object.assign({
13
- max_listeners: 10, // 最大监听器数量
14
- default_namespace: 'default', // 默认命名空间
15
- chain_enabled: true, // 是否启用链式触发
16
- auto_clean: true, // 是否自动清理空的事件列表
17
- error_handler: null, // 全局错误处理函数
18
- pause_enabled: true // 是否启用暂停功能
19
- }, config || {});
20
+ this.config = {
21
+ ...Eventer.config,
22
+ ...config || {}
23
+ };
20
24
  // 是否为插件
21
25
  this._is_plugin = false;
22
26
  // 事件字典 - 支持命名空间
@@ -442,7 +446,7 @@ Eventer.prototype._removeEvents = function (namespace, key, arr) {
442
446
  Eventer.prototype._autoCleanup = function (namespace, key) {
443
447
  try {
444
448
  if (this.config.auto_clean && this._dict[namespace] && this._dict[namespace][key] &&
445
- this._dict[namespace][key].length === 0) {
449
+ this._dict[namespace][key].length === 0) {
446
450
  delete this._dict[namespace][key];
447
451
  if (this._dict[namespace] && Object.keys(this._dict[namespace]).length === 0) {
448
452
  delete this._dict[namespace];
@@ -832,7 +836,7 @@ Eventer.prototype._callErrorHandler = function (e, obj, ctx) {
832
836
 
833
837
  /**
834
838
  * 竞争执行模式 - 返回第一个完成的结果
835
- * @param config
839
+ * @param {object} config 配置参数
836
840
  * @private
837
841
  */
838
842
  Eventer.prototype._executeRace = async function (config) {
@@ -1050,7 +1054,7 @@ Eventer.prototype.emit = function (key, ...params) {
1050
1054
  /**
1051
1055
  *
1052
1056
  */
1053
- cancel: () => {},
1057
+ cancel: () => { },
1054
1058
  error: emit_error
1055
1059
  };
1056
1060
  }
@@ -1341,7 +1345,7 @@ Eventer.prototype._removeEntireEvent = function (namespace, event_key, full_key)
1341
1345
  if (chain_key === full_key) {
1342
1346
  delete this._chain[chain_key];
1343
1347
  } else if (this._chain[chain_key] && Array.is_array(this._chain[chain_key]) &&
1344
- this._chain[chain_key].includes(full_key)) {
1348
+ this._chain[chain_key].includes(full_key)) {
1345
1349
  delete this._chain[chain_key];
1346
1350
  }
1347
1351
  }
@@ -1447,7 +1451,7 @@ Eventer.prototype.getEvents = function (key) {
1447
1451
  const { namespace, key: event_key } = this._parseKey(key);
1448
1452
  return this._dict[namespace] &&
1449
1453
 
1450
- this._dict[namespace][event_key] ? [...this._dict[namespace][event_key]] : [];
1454
+ this._dict[namespace][event_key] ? [...this._dict[namespace][event_key]] : [];
1451
1455
  }
1452
1456
  // 返回深拷贝的所有事件
1453
1457
  const result = {};
@@ -1565,7 +1569,7 @@ Eventer.prototype.count = function (key) {
1565
1569
  const { namespace, key: event_key } = this._parseKey(key);
1566
1570
  return this._dict[namespace] &&
1567
1571
 
1568
- this._dict[namespace][event_key] ? this._dict[namespace][event_key].length : 0;
1572
+ this._dict[namespace][event_key] ? this._dict[namespace][event_key].length : 0;
1569
1573
  }
1570
1574
 
1571
1575
  // 统计所有事件
package/lib/file.js CHANGED
@@ -24,9 +24,8 @@ var ncp = require('ncp').ncp;
24
24
  require('./global.js');
25
25
 
26
26
  /**
27
- * @description 判断是否文件
28
- * @param {string} fileOrDir 文件或目录
29
- * @param file_or_dir
27
+ * 判断是否为文件
28
+ * @param {string} file_or_dir 文件或目录
30
29
  * @returns {boolean} 是文件返回true,否则返回false
31
30
  */
32
31
  function isFile(file_or_dir) {
@@ -92,15 +91,16 @@ function validateFilePath(file) {
92
91
  return null;
93
92
  }
94
93
 
95
- /**
96
- *
97
- * @param file
98
- * @param dir
99
- */
94
+ /**
95
+ * 补全文件路径
96
+ * @param {string} file 文件路径
97
+ * @param {string} dir 当前目录
98
+ * @returns {string} 完整路径
99
+ */
100
100
  function fullname(file, dir) {
101
- var validation_result = validateFilePath(file);
102
- if (validation_result) {
103
- return validation_result;
101
+ var result = validateFilePath(file);
102
+ if (result) {
103
+ return result;
104
104
  }
105
105
 
106
106
  // 处理以 / 开头的路径(从项目启动位置)
@@ -278,7 +278,7 @@ File.prototype.copy = function (source, target) {
278
278
  * @param {string} file 文件路径
279
279
  * @returns {boolean} 删除成功返回true,否则返回false
280
280
  */
281
- File.prototype.delete = function (file) {
281
+ File.prototype.del = function (file) {
282
282
  if (!file || typeof file !== 'string') {
283
283
  throw new Error('file参数必须是非空字符串');
284
284
  }
@@ -404,9 +404,9 @@ function getFile(list, dir, keyword) {
404
404
  * 目录类函数
405
405
  */
406
406
  class Dir {
407
- /**
408
- *
409
- */
407
+ /**
408
+ *
409
+ */
410
410
  constructor() {
411
411
  // 构造函数,仅用于初始化
412
412
  }
@@ -416,7 +416,7 @@ class Dir {
416
416
  * 补全目录路径
417
417
  * @param {string} dir 目录路径
418
418
  * @param {string} baseDir 基础目录
419
- * @param base_dir
419
+ * @param base_dir
420
420
  * @returns {string} 完整路径
421
421
  */
422
422
  Dir.prototype.fullname = function (dir, base_dir) {
@@ -467,6 +467,15 @@ Dir.prototype.del = function (dir, func) {
467
467
  rimrafSync(dir.fullname(), func);
468
468
  };
469
469
 
470
+ /**
471
+ * @description 判断目录是否存在
472
+ * @param {string} dir 目录路径
473
+ * @returns {boolean} 存在返回true, 否则返回false
474
+ */
475
+ Dir.prototype.exists = function (dir) {
476
+ return existsSync(dir.fullname());
477
+ };
478
+
470
479
  /** === 文件类函数 === */
471
480
  /**
472
481
  * @description 补全路径
@@ -507,7 +516,7 @@ String.prototype.copyFile = function (file) {
507
516
  /**
508
517
  * @description 复制目录
509
518
  * @param {string} file 保存路径
510
- * @param func
519
+ * @param func
511
520
  * @returns {boolean} 复制成功返回true, 失败返回false
512
521
  */
513
522
  String.prototype.copyDir = function (file, func) {
@@ -697,7 +706,7 @@ String.prototype.delDir = function (dir, func) {
697
706
  /**
698
707
  * @创建路径
699
708
  * @param {string} dir 文件路径
700
- * @param dirbase
709
+ * @param dirbase
701
710
  */
702
711
  String.prototype.addDir = function (dirbase) {
703
712
  var d = (this + '').fullname(dirbase);
package/lib/lang.js CHANGED
@@ -5,10 +5,7 @@ require('./global.js');
5
5
  * @class
6
6
  */
7
7
  class Lang {
8
- /**
9
- *
10
- */
11
- static get config() {
8
+ static config() {
12
9
  return {
13
10
  zhCn: {},
14
11
  en: {},
@@ -21,7 +18,7 @@ class Lang {
21
18
  * @param {object} config - 配置参数
22
19
  */
23
20
  constructor(config) {
24
- this.config = Object.assign({}, Lang.config);
21
+ this.config = {...Lang.config, ...config || {}};
25
22
 
26
23
  // 是否为插件
27
24
  this.is_plugin = false;
package/lib/logger.js CHANGED
@@ -1,15 +1,15 @@
1
1
  const { Event } = require('./event.js');
2
2
  require('colors');
3
3
 
4
- // if(!console.debug){
5
- // console.debug = console.log;
6
- // }
7
- // if(!console.success){
8
- // console.success = console.info;
9
- // }
10
- // if(!console.fatal){
11
- // console.fatal = console.error;
12
- // }
4
+ if (!console.debug) {
5
+ console.debug = console.log;
6
+ }
7
+ if (!console.success) {
8
+ console.success = console.info;
9
+ }
10
+ if (!console.fatal) {
11
+ console.fatal = console.error;
12
+ }
13
13
 
14
14
  /**
15
15
  * 日志类
@@ -26,9 +26,9 @@ class Logger extends Event {
26
26
  */
27
27
  this.is_plugin = false;
28
28
  /**
29
- * 日志对象
30
- * @type {object} - 日志对象, 默认值: console
31
- */
29
+ * 日志对象
30
+ * @type {object} - 日志对象, 默认值: console
31
+ */
32
32
  this._logger = console;
33
33
  }
34
34
  }
package/lib/object.js CHANGED
@@ -387,7 +387,7 @@ function toXml(source, format, attributes, cdata = false) {
387
387
 
388
388
  if (cdata) {
389
389
  options.cdataPropName = cdata ? '_cdata' : undefined;
390
- source = toCDATA(Object.assign({}, source));
390
+ source = toCDATA({...source});
391
391
  }
392
392
 
393
393
  const builder = new XMLBuilder(options);
@@ -547,9 +547,10 @@ function _copyObject(source, deep, depth) {
547
547
  return new_obj;
548
548
  } else {
549
549
  // 浅层拷贝对象
550
- return Object.assign({}, source);
550
+ return {...source};
551
551
  }
552
552
  }
553
+
553
554
  /**
554
555
  * @description 获取对象的属性名数组
555
556
  * @param {object} source 源对象
package/lib/timer.js CHANGED
@@ -4,18 +4,22 @@ const { Base } = require('./base.js');
4
4
  * @description 定时器类
5
5
  */
6
6
  class Timer extends Base {
7
+ static config = {
8
+ name: 'Timer',
9
+ // 定时器间隔时间
10
+ interval: 1000,
11
+ // 是否自动移除有问题的任务
12
+ remove_faulty_tasks: false
13
+ };
7
14
  /**
8
15
  * @description 定时器构造函数
9
16
  * @param {object} config 配置参数
10
17
  */
11
18
  constructor(config) {
12
- super(Object.assign({
13
- name: 'Timer',
14
- // 定时器间隔时间
15
- interval: 1000,
16
- // 是否自动移除有问题的任务
17
- remove_faulty_tasks: false
18
- }, config));
19
+ super({
20
+ ...Timer.config,
21
+ ...config || {}
22
+ });
19
23
  // 是否为插件
20
24
  this.is_plugin = false;
21
25
  // 定时器核心
@@ -165,10 +169,10 @@ Timer.prototype.model = function (obj) {
165
169
  throw new Error('Timer: model方法参数必须是一个非空对象');
166
170
  }
167
171
 
168
- return Object.assign({
172
+ return {
169
173
  name: 'anonymous',
170
- run: function () { }
171
- }, obj);
174
+ run: function () { }, ...obj
175
+ }
172
176
  };
173
177
 
174
178
  /**
package/lib/validator.js CHANGED
@@ -38,12 +38,12 @@ class Validator {
38
38
  */
39
39
  static _getBasicContact() {
40
40
  return {
41
- 'phone': /^0?(13|14|15|16|17|18|19)[0-9]{9}$/,
42
- 'email': /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
43
- 'idcard': new RegExp('^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(1[0-2]))' +
44
- '(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$'),
45
- 'bankcard': /^[1-9]\d{14,18}$/,
46
- 'postcode': /^[1-9]\d{5}$/
41
+ phone: /^0?(13|14|15|16|17|18|19)[0-9]{9}$/,
42
+ email: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
43
+ idcard: new RegExp('^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(1[0-2]))' +
44
+ '(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$'),
45
+ bankcard: /^[1-9]\d{14,18}$/,
46
+ postcode: /^[1-9]\d{5}$/
47
47
  };
48
48
  }
49
49
 
@@ -53,16 +53,16 @@ class Validator {
53
53
  */
54
54
  static _getBasicDateTime() {
55
55
  return {
56
- 'date': new RegExp('^\\d{4}(-|\\/|\\.)(0[1-9]|1[012]|[1-9])' +
56
+ date: new RegExp('^\\d{4}(-|\\/|\\.)(0[1-9]|1[012]|[1-9])' +
57
57
  '(-|\\/|\\.)([12][0-9]|0[1-9]|3[01]|[1-9])$'),
58
- 'time': new RegExp('^([01][0-9]|2[0-3]):([0-4][0-9]|5[0-9])' +
59
- '(:([0-4][0-9]|5[0-9]))?$'),
60
- 'datetime': new RegExp('^\\d{4}(-|\\/|\\.)(0[1-9]|1[012]|[1-9])' +
61
- '(-|\\/|\\.)([12][0-9]|0[1-9]|3[01]|[1-9])' +
62
- ' ([01][0-9]|2[0-3]):([0-4][0-9]|5[0-9])' +
63
- '(:([0-4][0-9]|5[0-9]))?$'),
64
- 'dateiso': new RegExp('^\\d{4}-(0[1-9]|1[012]|[1-9])-([12][0-9]|0[1-9]|3[01]|[1-9])' +
65
- '( ([01][0-9]|2[0-3]):([0-4][0-9]|5[0-9])(:([0-4][0-9]|5[0-9]))?)?$')
58
+ time: new RegExp('^([01][0-9]|2[0-3]):([0-4][0-9]|5[0-9])' +
59
+ '(:([0-4][0-9]|5[0-9]))?$'),
60
+ datetime: new RegExp('^\\d{4}(-|\\/|\\.)(0[1-9]|1[012]|[1-9])' +
61
+ '(-|\\/|\\.)([12][0-9]|0[1-9]|3[01]|[1-9])' +
62
+ ' ([01][0-9]|2[0-3]):([0-4][0-9]|5[0-9])' +
63
+ '(:([0-4][0-9]|5[0-9]))?$'),
64
+ dateiso: new RegExp('^\\d{4}-(0[1-9]|1[012]|[1-9])-([12][0-9]|0[1-9]|3[01]|[1-9])' +
65
+ '( ([01][0-9]|2[0-3]):([0-4][0-9]|5[0-9])(:([0-4][0-9]|5[0-9]))?)?$')
66
66
  };
67
67
  }
68
68
 
@@ -81,7 +81,7 @@ class Validator {
81
81
  'chinese': /^[\u4e00-\u9fa5]+$/,
82
82
  'filename': /^[^\\/:*?"<>|]+$/,
83
83
  'licenseplate': new RegExp('^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领]' +
84
- '[A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$')
84
+ '[A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$')
85
85
  };
86
86
  }
87
87
 
@@ -91,15 +91,15 @@ class Validator {
91
91
  */
92
92
  static _getBasicNetwork() {
93
93
  return {
94
- 'url': new RegExp('^((https|http|ftp|rtsp|mms)?:\\/\\/)' +
94
+ url: new RegExp('^((https|http|ftp|rtsp|mms)?:\\/\\/)' +
95
95
  '[^\\s]+', 'gi'),
96
- 'domain': new RegExp('^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}' +
97
- '(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$'),
98
- 'ipv4': new RegExp('^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}' +
99
- '(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$'),
100
- 'ipv6': /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
101
- 'port': new RegExp('^([1-9]\\d{0,3}|[1-5]\\d{4}|6[0-4]\\d{3}|' +
102
- '65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$')
96
+ domain: new RegExp('^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}' +
97
+ '(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$'),
98
+ ipv4: new RegExp('^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}' +
99
+ '(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$'),
100
+ ipv6: /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
101
+ port: new RegExp('^([1-9]\\d{0,3}|[1-5]\\d{4}|6[0-4]\\d{3}|' +
102
+ '65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$')
103
103
  };
104
104
  }
105
105
 
@@ -142,12 +142,12 @@ class Validator {
142
142
  */
143
143
  static _getBasicData() {
144
144
  return {
145
- 'number': /^[1-9]+[0-9]*(\.[0-9]+|[0-9]*)|0\.[0-9]+|0$/,
146
- 'num': /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/,
147
- 'digits': /^[0-9]+$/,
148
- 'money': /^(\d{1,3}(,\d{3})*|\d+)(\.\d{1,2})?$/,
149
- 'lat': /^-?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,
150
- 'lng': /^-?((1[0-7]\d|\d{1,2})(\.\d+)?|180(\.0+)?)$/
145
+ number: /^[1-9]+[0-9]*(\.[0-9]+|[0-9]*)|0\.[0-9]+|0$/,
146
+ num: /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/,
147
+ digits: /^[0-9]+$/,
148
+ money: /^(\d{1,3}(,\d{3})*|\d+)(\.\d{1,2})?$/,
149
+ lat: /^-?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,
150
+ lng: /^-?((1[0-7]\d|\d{1,2})(\.\d+)?|180(\.0+)?)$/
151
151
  };
152
152
  }
153
153
 
@@ -157,13 +157,13 @@ class Validator {
157
157
  */
158
158
  static _getBasicTech() {
159
159
  return {
160
- 'hex': /^[0-9a-fA-F]+$/,
161
- 'base64': /^[A-Za-z0-9+/]+={0,2}$/,
162
- 'uuid': new RegExp('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}' +
163
- '-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$'),
164
- 'mac': /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
165
- 'color': /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,
166
- 'html': new RegExp('^<([a-z]+)([^<]+)*(?:>(.*)<\\/\\1>|\\s+\\/>)$')
160
+ hex: /^[0-9a-fA-F]+$/,
161
+ base64: /^[A-Za-z0-9+/]+={0,2}$/,
162
+ uuid: new RegExp('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}' +
163
+ '-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$'),
164
+ mac: /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/,
165
+ color: /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,
166
+ html: new RegExp('^<([a-z]+)([^<]+)*(?:>(.*)<\\/\\1>|\\s+\\/>)$')
167
167
  };
168
168
  }
169
169
 
@@ -174,8 +174,8 @@ class Validator {
174
174
  static _getGeoFormats() {
175
175
  return {
176
176
  'coordinate': new RegExp('^-?(?:[0-8]?[0-9]|90)(?:\\.\\d{1,6})?,' +
177
- '-?(?:1[0-7][0-9]|180|[0-9]?[0-9])' +
178
- '(?:\\.\\d{1,6})?$'), // 经纬度坐标(纬度-90~90,经度-180~180)
177
+ '-?(?:1[0-7][0-9]|180|[0-9]?[0-9])' +
178
+ '(?:\\.\\d{1,6})?$'), // 经纬度坐标(纬度-90~90,经度-180~180)
179
179
  'address': /^[\u4e00-\u9fa5A-Za-z0-9\s\-#,./]{5,100}$/, // 详细地址
180
180
  'postal_code': /^[0-9]{6}$/, // 邮政编码
181
181
  'area_code': /^0[0-9]{2,3}$/, // 区号
@@ -187,16 +187,16 @@ class Validator {
187
187
  }
188
188
 
189
189
  /**
190
- * 构造函数
191
- * @param {*} config 配置项
192
- */
190
+ * 构造函数
191
+ * @param {object} config 配置项
192
+ */
193
193
  constructor(config) {
194
194
  this.config = {
195
195
 
196
196
  };
197
197
  /**
198
- * 验证格式
199
- */
198
+ * 验证格式
199
+ */
200
200
  this._format = Validator.format;
201
201
  this.setConfig(config);
202
202
  }
@@ -389,7 +389,7 @@ Validator.prototype.notNaN = function (val) {
389
389
  * @param {*} val 要验证的值
390
390
  * @returns {string} 通过返回空字符串,没通过返回错误信息
391
391
  */
392
- Validator.prototype.notEmpty = function (val) {
392
+ Validator.prototype.not_empty = function (val) {
393
393
  let bl = val !== undefined && val !== null && val !== '';
394
394
  if (!bl) {
395
395
  return `参数必须不是空值,实际值为:${val}`;
@@ -477,7 +477,7 @@ Validator.prototype.isRangeVal = function (val, min, max) {
477
477
  /**
478
478
  * 是否符合正则表达式
479
479
  * @param {string} val 要验证的值
480
- * @param {Regex} regex 正则表达式
480
+ * @param {object} regex 正则表达式
481
481
  * @returns {string} 通过返回空字符串,没通过返回错误信息
482
482
  */
483
483
  Validator.prototype.isRegex = function (val, regex) {
@@ -1278,7 +1278,7 @@ Validator.prototype.createRuleObject = function (options) {
1278
1278
  min,
1279
1279
  max,
1280
1280
  required: false,
1281
- notEmpty: false,
1281
+ not_empty: false,
1282
1282
  default: null,
1283
1283
  type,
1284
1284
  check_type,
@@ -1336,8 +1336,8 @@ Validator.prototype.checkRequired = function (val, rule) {
1336
1336
  if (tip) {
1337
1337
  return tip;
1338
1338
  }
1339
- if (rule.notEmpty) {
1340
- tip = this.notEmpty(val);
1339
+ if (rule.not_empty) {
1340
+ tip = this.not_empty(val);
1341
1341
  if (tip) {
1342
1342
  return tip;
1343
1343
  }
@@ -1453,20 +1453,20 @@ Validator.prototype.checkDifferent = function (val, rule, obj) {
1453
1453
  */
1454
1454
  Validator.prototype.validateNum = function (val, type) {
1455
1455
  switch (type) {
1456
- case 'int':
1457
- return this.isRange(val, -2147483648, 2147483647);
1458
- case 'mediumint':
1459
- return this.isRange(val, -8388608, 8388607);
1460
- case 'smallint':
1461
- return this.isRange(val, -32768, 32767);
1462
- case 'tinyint':
1463
- return this.isRange(val, -128, 127);
1464
- case 'double':
1465
- case 'float':
1466
- case 'bigint':
1467
- return this.isRange(val, -Number.MAX_VALUE, Number.MAX_VALUE);
1468
- default:
1469
- return `不支持的数字类型:${type}`;
1456
+ case 'int':
1457
+ return this.isRange(val, -2147483648, 2147483647);
1458
+ case 'mediumint':
1459
+ return this.isRange(val, -8388608, 8388607);
1460
+ case 'smallint':
1461
+ return this.isRange(val, -32768, 32767);
1462
+ case 'tinyint':
1463
+ return this.isRange(val, -128, 127);
1464
+ case 'double':
1465
+ case 'float':
1466
+ case 'bigint':
1467
+ return this.isRange(val, -Number.MAX_VALUE, Number.MAX_VALUE);
1468
+ default:
1469
+ return `不支持的数字类型:${type}`;
1470
1470
  }
1471
1471
  };
1472
1472
 
@@ -1478,17 +1478,17 @@ Validator.prototype.validateNum = function (val, type) {
1478
1478
  */
1479
1479
  Validator.prototype.validateStr = function (val, type) {
1480
1480
  switch (type) {
1481
- case 'varchar':
1482
- // mysql varchar最大长度
1483
- return this.isLen(val, 0, 255);
1484
- case 'text':
1485
- // mysql text最大长度
1486
- return this.isLen(val, 0, 65535);
1487
- case 'longtext':
1488
- // mysql longtext最大长度
1489
- return this.isLen(val, 0, 4294967295);
1490
- default:
1491
- return `不支持的字符串类型:${type}`;
1481
+ case 'varchar':
1482
+ // mysql varchar最大长度
1483
+ return this.isLen(val, 0, 255);
1484
+ case 'text':
1485
+ // mysql text最大长度
1486
+ return this.isLen(val, 0, 65535);
1487
+ case 'longtext':
1488
+ // mysql longtext最大长度
1489
+ return this.isLen(val, 0, 4294967295);
1490
+ default:
1491
+ return `不支持的字符串类型:${type}`;
1492
1492
  }
1493
1493
  };
1494
1494
 
@@ -1550,13 +1550,14 @@ Validator.prototype.filterEmpty = function (obj) {
1550
1550
  if (!bl) {
1551
1551
  throw new Error(`参数必须是对象,实际类型为:${type}`);
1552
1552
  }
1553
- for (let key in obj) {
1554
- let val = obj[key];
1553
+ let o = {...obj};
1554
+ for (let key in o) {
1555
+ let val = o[key];
1555
1556
  if (val === '' || val === null || val === undefined) {
1556
- delete obj[key];
1557
+ delete o[key];
1557
1558
  }
1558
1559
  }
1559
- return obj;
1560
+ return o;
1560
1561
  };
1561
1562
 
1562
1563
  /**
@@ -1656,9 +1657,9 @@ Number.prototype.isMax = function (max) {
1656
1657
  * 检查字符串是否为空
1657
1658
  * @returns {boolean} 是否为空
1658
1659
  */
1659
- String.prototype.notEmpty = function () {
1660
+ String.prototype.not_empty = function () {
1660
1661
  let str = this + '';
1661
- let tip = validator.notEmpty(str);
1662
+ let tip = validator.not_empty(str);
1662
1663
  if (tip) {
1663
1664
  throw new TypeError(tip);
1664
1665
  }
@@ -1775,7 +1776,7 @@ String.prototype.isName = function () {
1775
1776
  * 检查数组是否为空
1776
1777
  * @returns {Array} 原始数组对象
1777
1778
  */
1778
- Array.prototype.notEmpty = function () {
1779
+ Array.prototype.not_empty = function () {
1779
1780
  if (this.length === 0) {
1780
1781
  throw new TypeError('数组不能为空');
1781
1782
  }
@@ -1809,7 +1810,7 @@ Array.prototype.contains = function (element) {
1809
1810
  };
1810
1811
 
1811
1812
  // Object原型方法 - 设置为不可枚举,避免影响for...in循环
1812
- Object.defineProperty(Object.prototype, 'notEmpty', {
1813
+ Object.defineProperty(Object.prototype, 'not_empty', {
1813
1814
  value: function () {
1814
1815
  if (Object.keys(this).length === 0) {
1815
1816
  throw new TypeError('对象不能为空');
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "mm_expand",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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": {
7
- "test": "node test/index.js",
7
+ "test": "node tests/index.js",
8
8
  "lint": "eslint lib/**/*.js",
9
9
  "lint:fix": "eslint lib/**/*.js --fix",
10
10
  "typecheck": "echo 'JavaScript项目无需类型检查'",
@@ -33,24 +33,23 @@
33
33
  "homepage": "https://gitee.com/qiuwenwu91/mm_expand#readme",
34
34
  "dependencies": {
35
35
  "colors": "^1.4.0",
36
- "fast-xml-parser": "^5.3.2",
36
+ "fast-xml-parser": "^5.5.9",
37
37
  "json5": "^2.2.3",
38
38
  "ncp": "^2.0.0",
39
39
  "pinyinlite": "^1.2.1",
40
- "rimraf": "^6.1.2"
40
+ "rimraf": "^6.1.3"
41
41
  },
42
42
  "directories": {
43
43
  "lib": "lib",
44
44
  "test": "test"
45
45
  },
46
46
  "devDependencies": {
47
- "@typescript-eslint/eslint-plugin": "^8.49.0",
48
- "@typescript-eslint/parser": "^8.49.0",
49
- "eslint": "^9.39.2",
50
- "eslint-plugin-jsdoc": "^61.5.0"
47
+ "eslint": "^10.1.0",
48
+ "eslint-plugin-jsdoc": "^62.9.0",
49
+ "mm_eslint": "^1.7.1"
51
50
  },
52
51
  "engines": {
53
- "node": ">=12.0.0"
52
+ "node": ">=14.0.0"
54
53
  },
55
54
  "files": [
56
55
  "lib/",