mm_expand 2.4.2 → 2.4.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/lib/base.js +3 -3
- package/lib/errors.js +1 -1
- package/lib/event.js +7 -7
- package/lib/eventer.js +2294 -2422
- package/lib/file.js +797 -797
- package/lib/global.js +2 -1
- package/lib/lang.js +6 -6
- package/lib/logger.js +2 -2
- package/lib/string.js +9 -9
- package/package.json +1 -1
package/lib/global.js
CHANGED
|
@@ -21,6 +21,7 @@ function sleep(milli_seconds, obj, key) {
|
|
|
21
21
|
|
|
22
22
|
if (!obj) {
|
|
23
23
|
simpleSleep(end_time);
|
|
24
|
+
return;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
if (key) {
|
|
@@ -278,7 +279,7 @@ if (!global.$) {
|
|
|
278
279
|
}
|
|
279
280
|
|
|
280
281
|
// 先判断基本类型
|
|
281
|
-
compareBasic(source, target);
|
|
282
|
+
var basic_result = compareBasic(source, target);
|
|
282
283
|
if (basic_result !== null) {
|
|
283
284
|
return basic_result;
|
|
284
285
|
}
|
package/lib/lang.js
CHANGED
|
@@ -6,7 +6,7 @@ const { Base } = require('./base.js');
|
|
|
6
6
|
*/
|
|
7
7
|
class Lang extends Base {
|
|
8
8
|
static config = {
|
|
9
|
-
|
|
9
|
+
zh_cn: {},
|
|
10
10
|
en: {},
|
|
11
11
|
default: 'zh_cn',
|
|
12
12
|
fallback: true
|
|
@@ -27,7 +27,7 @@ class Lang extends Base {
|
|
|
27
27
|
en(count) {
|
|
28
28
|
return count === 1 ? 0 : 1;
|
|
29
29
|
},
|
|
30
|
-
|
|
30
|
+
zh_cn(count) {
|
|
31
31
|
return 0;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
@@ -345,8 +345,8 @@ Lang.prototype.formatDate = function (dt, format = 'YYYY-MM-DD hh:mm:ss') {
|
|
|
345
345
|
* @param {number} num - 要格式化的数字
|
|
346
346
|
* @param {object} [options] - 选项
|
|
347
347
|
* @param {number} [options.decimals=2] - 小数位数
|
|
348
|
-
* @param {string} [options.
|
|
349
|
-
* @param {string} [options.
|
|
348
|
+
* @param {string} [options.decimal_separator] - 小数分隔符
|
|
349
|
+
* @param {string} [options.thousands_separator] - 千位分隔符
|
|
350
350
|
* @returns {string} 格式化后的数字字符串
|
|
351
351
|
*/
|
|
352
352
|
Lang.prototype.formatNumber = function (num, options = {}) {
|
|
@@ -359,8 +359,8 @@ Lang.prototype.formatNumber = function (num, options = {}) {
|
|
|
359
359
|
var decimals = typeof opt.decimals === 'number' ? opt.decimals : 2;
|
|
360
360
|
|
|
361
361
|
// 获取语言特定的分隔符
|
|
362
|
-
var decimal_sepa = opt.
|
|
363
|
-
var thou_sepa = opt.
|
|
362
|
+
var decimal_sepa = opt.decimal_separator || '.';
|
|
363
|
+
var thou_sepa = opt.thousands_separator || ',';
|
|
364
364
|
|
|
365
365
|
// 格式化数字
|
|
366
366
|
var parts = num.toFixed(decimals).split('.');
|
package/lib/logger.js
CHANGED
|
@@ -67,7 +67,7 @@ Logger.prototype.debug = function (message, ...args) {
|
|
|
67
67
|
this.emit('debug:after', ctx);
|
|
68
68
|
} catch (error) {
|
|
69
69
|
// 日志错误处理
|
|
70
|
-
this.
|
|
70
|
+
this.getLogger().error(error);
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
|
|
@@ -130,7 +130,7 @@ Logger.prototype.warn = function (message, ...args) {
|
|
|
130
130
|
this.emit('warn:after', ctx);
|
|
131
131
|
} catch (error) {
|
|
132
132
|
// 日志错误处理
|
|
133
|
-
this.
|
|
133
|
+
this.getLogger().error(error);
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
|
package/lib/string.js
CHANGED
|
@@ -57,7 +57,7 @@ String.prototype.aesEncode = function (key, iv) {
|
|
|
57
57
|
chunks.push(cipher.final(encoding));
|
|
58
58
|
return chunks.join('');
|
|
59
59
|
} catch (error) {
|
|
60
|
-
throw new Error('AES加密错误:'
|
|
60
|
+
throw new Error('AES加密错误: ' + error.message);
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
|
|
@@ -83,7 +83,7 @@ String.prototype.aesDecode = function (key, iv) {
|
|
|
83
83
|
chunks.push(decipher.final(encoding));
|
|
84
84
|
return chunks.join('');
|
|
85
85
|
} catch (error) {
|
|
86
|
-
throw new Error('AES解密错误:'
|
|
86
|
+
throw new Error('AES解密错误: ' + error.message);
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
|
|
@@ -123,7 +123,7 @@ String.prototype.toJson = function () {
|
|
|
123
123
|
try {
|
|
124
124
|
return json5.parse(this);
|
|
125
125
|
} catch (error) {
|
|
126
|
-
throw new Error('json
|
|
126
|
+
throw new Error('json反序列化错误: ' + error.message);
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
129
|
/**
|
|
@@ -135,7 +135,7 @@ String.prototype.toXml = function () {
|
|
|
135
135
|
const parser = new XmlParser();
|
|
136
136
|
return parser.parse(this);
|
|
137
137
|
} catch (error) {
|
|
138
|
-
throw new Error('xml
|
|
138
|
+
throw new Error('xml反序列化错误: ' + error.message);
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
/**
|
|
@@ -385,8 +385,8 @@ String.prototype.addSeconds = function (seconds, format) {
|
|
|
385
385
|
}
|
|
386
386
|
|
|
387
387
|
// 降级处理
|
|
388
|
-
const
|
|
389
|
-
return format ?
|
|
388
|
+
const new_time = new Date(date.getTime() + seconds * 1000);
|
|
389
|
+
return format ? new_time.toISOString() : new_time;
|
|
390
390
|
};
|
|
391
391
|
|
|
392
392
|
/**
|
|
@@ -409,8 +409,8 @@ String.prototype.addDays = function (days, format) {
|
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
// 降级处理
|
|
412
|
-
const
|
|
413
|
-
return format ?
|
|
412
|
+
const new_time = new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
413
|
+
return format ? new_time.toISOString() : new_time;
|
|
414
414
|
};
|
|
415
415
|
|
|
416
416
|
/**
|
|
@@ -480,7 +480,7 @@ String.prototype.toRx = function (mode) {
|
|
|
480
480
|
let pattern = this.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
481
481
|
return new RegExp(pattern, _mode);
|
|
482
482
|
} catch (error) {
|
|
483
|
-
throw new Error('字符串转正则错误:'
|
|
483
|
+
throw new Error('字符串转正则错误: ' + error.message);
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
|