mm_expand 2.1.7 → 2.1.8
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/file.js +37 -36
- package/package.json +1 -1
package/lib/file.js
CHANGED
|
@@ -134,7 +134,7 @@ function fullname(file, dir) {
|
|
|
134
134
|
*/
|
|
135
135
|
class File extends Base {
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
137
|
+
* 构造函数,用于初始化文件类
|
|
138
138
|
*/
|
|
139
139
|
constructor(config) {
|
|
140
140
|
super(config);
|
|
@@ -150,7 +150,7 @@ class File extends Base {
|
|
|
150
150
|
File.prototype.fullname = fullname;
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
|
-
*
|
|
153
|
+
* 搜索目录下所有文件
|
|
154
154
|
* @param {string} dir 目录地址
|
|
155
155
|
* @param {string} keyword 搜索关键词
|
|
156
156
|
* @param {string} keyword_dir 目录搜素关键词
|
|
@@ -172,7 +172,7 @@ File.prototype.getAll = function (dir, keyword, keyword_dir) {
|
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
-
*
|
|
175
|
+
* 获取当前目录下所有文件
|
|
176
176
|
* @param {string} dir 目录地址
|
|
177
177
|
* @param {string} keyword 搜索关键词
|
|
178
178
|
* @returns {Array} 文件路径数组
|
|
@@ -184,7 +184,7 @@ File.prototype.get = function (dir, keyword) {
|
|
|
184
184
|
};
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
187
|
+
* 加载文件
|
|
188
188
|
* @param {string} file 文件路径
|
|
189
189
|
* @param {string} encode 编码方式
|
|
190
190
|
* @returns {string} 加载的文本
|
|
@@ -205,7 +205,7 @@ File.prototype.load = function (file, encode) {
|
|
|
205
205
|
};
|
|
206
206
|
|
|
207
207
|
/**
|
|
208
|
-
*
|
|
208
|
+
* 保存文件
|
|
209
209
|
* @param {string} file 文件路径
|
|
210
210
|
* @param {string} data 数据内容
|
|
211
211
|
* @param {string} encode 编码方式
|
|
@@ -231,7 +231,7 @@ File.prototype.save = function (file, data, encode) {
|
|
|
231
231
|
};
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
|
-
*
|
|
234
|
+
* 复制文件
|
|
235
235
|
* @param {string} source 文件原路径
|
|
236
236
|
* @param {string} target 目标路径
|
|
237
237
|
* @returns {boolean} 复制成功返回true,否则返回false
|
|
@@ -253,7 +253,7 @@ File.prototype.copy = function (source, target) {
|
|
|
253
253
|
};
|
|
254
254
|
|
|
255
255
|
/**
|
|
256
|
-
*
|
|
256
|
+
* 删除文件
|
|
257
257
|
* @param {string} file 文件路径
|
|
258
258
|
* @returns {boolean} 删除成功返回true,否则返回false
|
|
259
259
|
*/
|
|
@@ -271,7 +271,7 @@ File.prototype.del = function (file) {
|
|
|
271
271
|
};
|
|
272
272
|
|
|
273
273
|
/**
|
|
274
|
-
*
|
|
274
|
+
* 检查文件是否存在
|
|
275
275
|
* @param {string} file 文件路径
|
|
276
276
|
* @returns {boolean} 存在返回true,否则返回false
|
|
277
277
|
*/
|
|
@@ -283,7 +283,7 @@ File.prototype.exists = function (file) {
|
|
|
283
283
|
};
|
|
284
284
|
|
|
285
285
|
/**
|
|
286
|
-
*
|
|
286
|
+
* 读取文件内容
|
|
287
287
|
* @param {string} file 文件路径
|
|
288
288
|
* @param {string} encode 编码方式
|
|
289
289
|
* @returns {string} 文件内容
|
|
@@ -296,7 +296,7 @@ File.prototype.read = function (file, encode) {
|
|
|
296
296
|
};
|
|
297
297
|
|
|
298
298
|
/**
|
|
299
|
-
*
|
|
299
|
+
* 写入文件内容
|
|
300
300
|
* @param {string} file 文件路径
|
|
301
301
|
* @param {string} data 数据内容
|
|
302
302
|
* @param {string} encode 编码方式
|
|
@@ -310,7 +310,7 @@ File.prototype.write = function (file, data, encode) {
|
|
|
310
310
|
};
|
|
311
311
|
|
|
312
312
|
/**
|
|
313
|
-
*
|
|
313
|
+
* 搜索目录下所有目录
|
|
314
314
|
* @param {Array} list 结果路径数组
|
|
315
315
|
* @param {string} dir 目录地址
|
|
316
316
|
* @param {string} keyword 搜索关键词
|
|
@@ -334,7 +334,7 @@ function eachDir(list, dir, keyword) {
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
/**
|
|
337
|
-
*
|
|
337
|
+
* 获取当前目录下所有目录
|
|
338
338
|
* @param {Array} list 结果路径数组
|
|
339
339
|
* @param {string} dir 目录地址
|
|
340
340
|
* @param {string} keyword 搜索关键词
|
|
@@ -358,7 +358,7 @@ function getDir(list, dir, keyword) {
|
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
/**
|
|
361
|
-
*
|
|
361
|
+
* 添加文件路径
|
|
362
362
|
* @param {Array} list 结果路径数组
|
|
363
363
|
* @param {string} dir 目录地址
|
|
364
364
|
* @param {string} keyword 搜索关键词
|
|
@@ -401,7 +401,7 @@ class Dir extends Base {
|
|
|
401
401
|
Dir.prototype.fullname = fullname;
|
|
402
402
|
|
|
403
403
|
/**
|
|
404
|
-
*
|
|
404
|
+
* 搜索目录下所有目录
|
|
405
405
|
* @param {string} dir 目录地址
|
|
406
406
|
* @param {string} keyword 搜索关键词
|
|
407
407
|
* @returns {Array} 目录路径数组
|
|
@@ -413,7 +413,7 @@ Dir.prototype.getAll = function (dir, keyword) {
|
|
|
413
413
|
};
|
|
414
414
|
|
|
415
415
|
/**
|
|
416
|
-
*
|
|
416
|
+
* 搜索当前目录下所有目录
|
|
417
417
|
* @param {string} dir 目录地址
|
|
418
418
|
* @param {string} keyword 搜索关键词
|
|
419
419
|
* @returns {Array} 目录路径数组
|
|
@@ -435,7 +435,7 @@ Dir.prototype.copy = function (source, target, func) {
|
|
|
435
435
|
};
|
|
436
436
|
|
|
437
437
|
/**
|
|
438
|
-
*
|
|
438
|
+
* 删除目录
|
|
439
439
|
* @param {string} dir 目录路径
|
|
440
440
|
* @param {Function} func 回调函数
|
|
441
441
|
* @returns {boolean} 保存成功返回true,否则返回false
|
|
@@ -445,7 +445,7 @@ Dir.prototype.del = function (dir, func) {
|
|
|
445
445
|
};
|
|
446
446
|
|
|
447
447
|
/**
|
|
448
|
-
*
|
|
448
|
+
* 判断目录是否存在
|
|
449
449
|
* @param {string} dir 目录路径
|
|
450
450
|
* @returns {boolean} 存在返回true, 否则返回false
|
|
451
451
|
*/
|
|
@@ -455,7 +455,7 @@ Dir.prototype.exists = function (dir) {
|
|
|
455
455
|
|
|
456
456
|
/** === 文件类函数 === */
|
|
457
457
|
/**
|
|
458
|
-
*
|
|
458
|
+
* 补全路径
|
|
459
459
|
* @param {string} dir
|
|
460
460
|
* @returns {string} 全路径
|
|
461
461
|
*/
|
|
@@ -464,7 +464,7 @@ String.prototype.fullname = function (dir) {
|
|
|
464
464
|
};
|
|
465
465
|
|
|
466
466
|
/**
|
|
467
|
-
*
|
|
467
|
+
* 获取当前目录下所有文件
|
|
468
468
|
* @param {string} keyword 搜索关键词
|
|
469
469
|
* @returns {Array} 文件路径数组
|
|
470
470
|
*/
|
|
@@ -473,7 +473,7 @@ String.prototype.getFile = function (keyword) {
|
|
|
473
473
|
};
|
|
474
474
|
|
|
475
475
|
/**
|
|
476
|
-
*
|
|
476
|
+
* 搜索当前目录下所有目录
|
|
477
477
|
* @param {string} keyword 搜索关键词
|
|
478
478
|
* @returns {Array} 目录路径数组
|
|
479
479
|
*/
|
|
@@ -482,7 +482,7 @@ String.prototype.getDir = function (keyword) {
|
|
|
482
482
|
};
|
|
483
483
|
|
|
484
484
|
/**
|
|
485
|
-
*
|
|
485
|
+
* 复制文件
|
|
486
486
|
* @param {string} file 保存路径
|
|
487
487
|
* @returns {boolean} 复制成功返回true, 失败返回false
|
|
488
488
|
*/
|
|
@@ -491,7 +491,7 @@ String.prototype.copyFile = function (file) {
|
|
|
491
491
|
};
|
|
492
492
|
|
|
493
493
|
/**
|
|
494
|
-
*
|
|
494
|
+
* 复制目录
|
|
495
495
|
* @param {string} file 保存路径
|
|
496
496
|
* @param func
|
|
497
497
|
* @returns {boolean} 复制成功返回true, 失败返回false
|
|
@@ -529,21 +529,21 @@ String.prototype.isFile = function () {
|
|
|
529
529
|
};
|
|
530
530
|
|
|
531
531
|
/**
|
|
532
|
-
*
|
|
532
|
+
* 取路径
|
|
533
533
|
* @returns {string} 字符串
|
|
534
534
|
*/
|
|
535
535
|
String.prototype.dirname = function () {
|
|
536
536
|
return dirname(this + '');
|
|
537
537
|
};
|
|
538
538
|
/**
|
|
539
|
-
*
|
|
539
|
+
* 取基础名
|
|
540
540
|
* @returns {string} 字符串
|
|
541
541
|
*/
|
|
542
542
|
String.prototype.basename = function () {
|
|
543
543
|
return basename(this + '');
|
|
544
544
|
};
|
|
545
545
|
/**
|
|
546
|
-
*
|
|
546
|
+
* 取拓展名
|
|
547
547
|
* @returns {string} 字符串
|
|
548
548
|
*/
|
|
549
549
|
String.prototype.extname = function () {
|
|
@@ -552,7 +552,7 @@ String.prototype.extname = function () {
|
|
|
552
552
|
|
|
553
553
|
|
|
554
554
|
/**
|
|
555
|
-
*
|
|
555
|
+
* 保存文件
|
|
556
556
|
* @param {string} text 被保存的文本
|
|
557
557
|
* @returns {boolean} 保存成功返回true, 失败返回false
|
|
558
558
|
*/
|
|
@@ -567,16 +567,17 @@ String.prototype.saveText = function (text) {
|
|
|
567
567
|
};
|
|
568
568
|
|
|
569
569
|
/**
|
|
570
|
-
*
|
|
570
|
+
* 保存为JSON格式文件
|
|
571
571
|
* @param {object} obj 被保存的内容
|
|
572
572
|
* @param {boolean} format 是否格式化
|
|
573
|
+
* @param {number} space 格式化缩进空格数
|
|
573
574
|
* @returns {boolean} 保存成功返回true, 失败返回false
|
|
574
575
|
*/
|
|
575
|
-
String.prototype.saveJson = function (obj, format = true) {
|
|
576
|
+
String.prototype.saveJson = function (obj, format = true, space = 2) {
|
|
576
577
|
try {
|
|
577
578
|
var text = '';
|
|
578
579
|
if (format) {
|
|
579
|
-
text = JSON.stringify(obj, null,
|
|
580
|
+
text = JSON.stringify(obj, null, space);
|
|
580
581
|
} else {
|
|
581
582
|
text = JSON.stringify(obj);
|
|
582
583
|
}
|
|
@@ -589,7 +590,7 @@ String.prototype.saveJson = function (obj, format = true) {
|
|
|
589
590
|
};
|
|
590
591
|
|
|
591
592
|
/**
|
|
592
|
-
*
|
|
593
|
+
* 加载文件
|
|
593
594
|
* @param {string} encode 编码方式
|
|
594
595
|
* @returns {string} 加载的文本
|
|
595
596
|
*/
|
|
@@ -606,7 +607,7 @@ String.prototype.loadText = function (encode) {
|
|
|
606
607
|
};
|
|
607
608
|
|
|
608
609
|
/**
|
|
609
|
-
*
|
|
610
|
+
* 加载xml
|
|
610
611
|
* @param {string} file 当前路径
|
|
611
612
|
* @returns {string} 加载的文本
|
|
612
613
|
*/
|
|
@@ -626,7 +627,7 @@ String.prototype.loadXml = function (file) {
|
|
|
626
627
|
};
|
|
627
628
|
|
|
628
629
|
/**
|
|
629
|
-
*
|
|
630
|
+
* 加载json
|
|
630
631
|
* @param {string} file 当前路径
|
|
631
632
|
* @returns {object} 加载后转换的对象
|
|
632
633
|
*/
|
|
@@ -646,7 +647,7 @@ String.prototype.loadJson = function (file) {
|
|
|
646
647
|
};
|
|
647
648
|
|
|
648
649
|
/**
|
|
649
|
-
*
|
|
650
|
+
* 判断文件是否存在
|
|
650
651
|
* @param {string} file 当前路径
|
|
651
652
|
* @returns {boolean} 存在返回true, 不存在返回false
|
|
652
653
|
*/
|
|
@@ -655,7 +656,7 @@ String.prototype.hasFile = function (file) {
|
|
|
655
656
|
};
|
|
656
657
|
|
|
657
658
|
/**
|
|
658
|
-
*
|
|
659
|
+
* 删除文件
|
|
659
660
|
* @param {string} file 当前路径
|
|
660
661
|
*/
|
|
661
662
|
String.prototype.delFile = function (file) {
|
|
@@ -663,7 +664,7 @@ String.prototype.delFile = function (file) {
|
|
|
663
664
|
};
|
|
664
665
|
|
|
665
666
|
/**
|
|
666
|
-
*
|
|
667
|
+
* 判断目录是否存在
|
|
667
668
|
* @param {string} dir 当前路径
|
|
668
669
|
* @returns {boolean} 存在返回true, 不存在返回false
|
|
669
670
|
*/
|
|
@@ -672,7 +673,7 @@ String.prototype.hasDir = function (dir) {
|
|
|
672
673
|
};
|
|
673
674
|
|
|
674
675
|
/**
|
|
675
|
-
*
|
|
676
|
+
* 删除目录
|
|
676
677
|
* @param {string} dir 当前路径
|
|
677
678
|
* @param {Function} func 回调函数
|
|
678
679
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.8",
|
|
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": {
|