mm_expand 2.1.3 → 2.1.4
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 +9 -0
- package/lib/file.js +11 -39
- package/lib/global.js +22 -22
- package/lib/lang.js +8 -24
- package/package.json +1 -1
package/lib/base.js
CHANGED
|
@@ -34,6 +34,7 @@ class Base extends Event {
|
|
|
34
34
|
// 监听事件
|
|
35
35
|
this._listen();
|
|
36
36
|
}
|
|
37
|
+
|
|
37
38
|
/**
|
|
38
39
|
* 获取当前状态
|
|
39
40
|
* @returns {string} 当前状态
|
|
@@ -94,6 +95,12 @@ Base.prototype._onDestroy = function () {
|
|
|
94
95
|
});
|
|
95
96
|
};
|
|
96
97
|
|
|
98
|
+
/**
|
|
99
|
+
* 预设值
|
|
100
|
+
*/
|
|
101
|
+
Base.prototype._preset = function () {
|
|
102
|
+
};
|
|
103
|
+
|
|
97
104
|
/**
|
|
98
105
|
* 设置配置参数
|
|
99
106
|
* @param {object} config 主要配置
|
|
@@ -106,6 +113,8 @@ Base.prototype.setConfig = function (config) {
|
|
|
106
113
|
}
|
|
107
114
|
Object.assign(this.config, config);
|
|
108
115
|
}
|
|
116
|
+
// 初始化设置
|
|
117
|
+
this._preset();
|
|
109
118
|
return this.config;
|
|
110
119
|
};
|
|
111
120
|
|
package/lib/file.js
CHANGED
|
@@ -21,7 +21,7 @@ const {
|
|
|
21
21
|
rimrafSync
|
|
22
22
|
} = require('rimraf');
|
|
23
23
|
var ncp = require('ncp').ncp;
|
|
24
|
-
require('./
|
|
24
|
+
const { Base } = require('./base.js');
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* 判断是否为文件
|
|
@@ -132,38 +132,12 @@ function fullname(file, dir) {
|
|
|
132
132
|
/**
|
|
133
133
|
* 文件类函数
|
|
134
134
|
*/
|
|
135
|
-
class File {
|
|
135
|
+
class File extends Base {
|
|
136
136
|
/**
|
|
137
|
-
* @description
|
|
137
|
+
* @description 构造函数,用于初始化文件类
|
|
138
138
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
* @description 构造函数,用于初始化文件类
|
|
142
|
-
*/
|
|
143
|
-
constructor() {
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* @description 设置日志对象
|
|
147
|
-
* @param {object} logger 日志对象
|
|
148
|
-
*/
|
|
149
|
-
setLogger(logger) {
|
|
150
|
-
this.#logger = logger;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* @description 获取日志对象
|
|
154
|
-
* @returns {object} 日志对象
|
|
155
|
-
*/
|
|
156
|
-
getLogger() {
|
|
157
|
-
return this.#logger;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @description 日志输出
|
|
161
|
-
* @param {string} level 日志级别
|
|
162
|
-
* @param {string} message 日志消息
|
|
163
|
-
* @param {...any} args 日志参数
|
|
164
|
-
*/
|
|
165
|
-
log(level, message, ...args) {
|
|
166
|
-
this.getLogger()[level](`[${this.constructor.name}] ${message}`, ...args);
|
|
139
|
+
constructor(config) {
|
|
140
|
+
super(config);
|
|
167
141
|
}
|
|
168
142
|
}
|
|
169
143
|
|
|
@@ -382,6 +356,7 @@ function getDir(list, dir, keyword) {
|
|
|
382
356
|
}
|
|
383
357
|
}
|
|
384
358
|
}
|
|
359
|
+
|
|
385
360
|
/**
|
|
386
361
|
* @description 添加文件路径
|
|
387
362
|
* @param {Array} list 结果路径数组
|
|
@@ -408,25 +383,22 @@ function getFile(list, dir, keyword) {
|
|
|
408
383
|
/**
|
|
409
384
|
* 目录类函数
|
|
410
385
|
*/
|
|
411
|
-
class Dir {
|
|
386
|
+
class Dir extends Base {
|
|
412
387
|
/**
|
|
413
388
|
*
|
|
414
389
|
*/
|
|
415
|
-
constructor() {
|
|
416
|
-
|
|
390
|
+
constructor(config) {
|
|
391
|
+
super(config);
|
|
417
392
|
}
|
|
418
393
|
}
|
|
419
394
|
|
|
420
395
|
/**
|
|
421
396
|
* 补全目录路径
|
|
422
397
|
* @param {string} dir 目录路径
|
|
423
|
-
* @param {string}
|
|
424
|
-
* @param base_dir
|
|
398
|
+
* @param {string} base_dir 基础目录
|
|
425
399
|
* @returns {string} 完整路径
|
|
426
400
|
*/
|
|
427
|
-
Dir.prototype.fullname =
|
|
428
|
-
return fullname(dir, base_dir);
|
|
429
|
-
};
|
|
401
|
+
Dir.prototype.fullname = fullname;
|
|
430
402
|
|
|
431
403
|
/**
|
|
432
404
|
* @description 搜索目录下所有目录
|
package/lib/global.js
CHANGED
|
@@ -11,7 +11,7 @@ Set.prototype.del = Set.prototype.delete;
|
|
|
11
11
|
/**
|
|
12
12
|
* @description 延迟执行(休眠)
|
|
13
13
|
* @param {number} milliSeconds 毫秒
|
|
14
|
-
* @param milli_seconds
|
|
14
|
+
* @param milli_seconds
|
|
15
15
|
* @param {object} obj 判断对象或函数
|
|
16
16
|
* @param {string} key 判断的对象属性, 为存在的情况下提成退出循环
|
|
17
17
|
* @example var obj = {ok: false}; sleep(2000, obj, 'ok');
|
|
@@ -34,7 +34,7 @@ function sleep(milli_seconds, obj, key) {
|
|
|
34
34
|
/**
|
|
35
35
|
* 简单休眠
|
|
36
36
|
* @param {number} endTime 结束时间
|
|
37
|
-
* @param end_time
|
|
37
|
+
* @param end_time
|
|
38
38
|
*/
|
|
39
39
|
function simpleSleep(end_time) {
|
|
40
40
|
while (new Date().getTime() < end_time) {
|
|
@@ -45,7 +45,7 @@ function simpleSleep(end_time) {
|
|
|
45
45
|
/**
|
|
46
46
|
* 带键值检查的休眠
|
|
47
47
|
* @param {number} endTime 结束时间
|
|
48
|
-
* @param end_time
|
|
48
|
+
* @param end_time
|
|
49
49
|
* @param {object} obj 判断对象
|
|
50
50
|
* @param {string} key 判断的对象属性
|
|
51
51
|
*/
|
|
@@ -60,7 +60,7 @@ function sleepWithKey(end_time, obj, key) {
|
|
|
60
60
|
/**
|
|
61
61
|
* 带函数检查的休眠
|
|
62
62
|
* @param {number} endTime 结束时间
|
|
63
|
-
* @param end_time
|
|
63
|
+
* @param end_time
|
|
64
64
|
* @param {Function} func 判断函数
|
|
65
65
|
*/
|
|
66
66
|
function sleepWithFunc(end_time, func) {
|
|
@@ -245,13 +245,13 @@ if (!global.$) {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
/**
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
248
|
+
* 判断对象是否相似
|
|
249
|
+
* @param {object} source 被判断对象
|
|
250
|
+
* @param {object} target 用作判断的对象
|
|
251
|
+
* @param {boolean} exact 是否完全相同
|
|
252
|
+
* @param {number} depth 递归深度
|
|
253
|
+
* @returns {boolean} 相似返回true,否则返回false
|
|
254
|
+
*/
|
|
255
255
|
function compareObject(source, target, exact, depth) {
|
|
256
256
|
if (exact &&
|
|
257
257
|
Object.getOwnPropertyNames(source).length !== Object.getOwnPropertyNames(target).length) {
|
|
@@ -266,13 +266,13 @@ if (!global.$) {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
/**
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
269
|
+
* 判断对象是否相似
|
|
270
|
+
* @param {object} source 被判断对象
|
|
271
|
+
* @param {object} target 用作判断的对象
|
|
272
|
+
* @param {boolean} exact 是否完全相同
|
|
273
|
+
* @param {number} depth 递归深度,防止无限递归
|
|
274
|
+
* @returns {boolean} 相似返回true,否则返回false
|
|
275
|
+
*/
|
|
276
276
|
$.as = function (source, target, exact, depth = 0) {
|
|
277
277
|
// 防止无限递归,最大递归深度为10
|
|
278
278
|
if (depth > 10) {
|
|
@@ -295,10 +295,10 @@ if (!global.$) {
|
|
|
295
295
|
};
|
|
296
296
|
|
|
297
297
|
/**
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
* 将对象转换为查询字符串
|
|
299
|
+
* @param {object} obj 要转换的对象
|
|
300
|
+
* @returns {string} 查询字符串
|
|
301
|
+
*/
|
|
302
302
|
$.toQuery = function (obj) {
|
|
303
303
|
if (typeof obj !== 'object' || obj === null) {
|
|
304
304
|
return '';
|
package/lib/lang.js
CHANGED
|
@@ -40,35 +40,19 @@ class Lang extends Base {
|
|
|
40
40
|
return 0;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
|
|
44
|
-
// 初始化默认语言
|
|
45
|
-
this.now = this.config.default || 'zh_cn';
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
// /**
|
|
50
|
-
// * 设置配置参数
|
|
51
|
-
// * @param {object} config - 配置参数
|
|
52
|
-
// */
|
|
53
|
-
// Lang.prototype.setConfig = function(config) {
|
|
54
|
-
// if (config) {
|
|
55
|
-
// // 合并配置
|
|
56
|
-
// Object.assign(this.config, config);
|
|
57
|
-
|
|
58
|
-
// // 设置区域映射表
|
|
59
|
-
// if (config.locale) {
|
|
60
|
-
// this.locale = Object.assign(this.locale, config.locale);
|
|
61
|
-
// }
|
|
62
|
-
// }
|
|
63
|
-
// };
|
|
64
|
-
|
|
65
46
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {object} logger - 日志对象
|
|
47
|
+
* 预设值
|
|
68
48
|
*/
|
|
69
|
-
Lang.prototype.
|
|
70
|
-
|
|
71
|
-
|
|
49
|
+
Lang.prototype._preset = function () {
|
|
50
|
+
// 初始化默认语言
|
|
51
|
+
this.now = this.config.default || 'zh_cn';
|
|
52
|
+
let config = this.config;
|
|
53
|
+
// 设置区域映射表
|
|
54
|
+
if (config.locale) {
|
|
55
|
+
this.locale = Object.assign(this.locale || {}, config.locale);
|
|
72
56
|
}
|
|
73
57
|
};
|
|
74
58
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
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": {
|