mm_expand 1.5.7 → 1.5.9
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/index.js +58 -8
- package/package.json +3 -2
- package/test.js +27 -4
- package/demo/test/image/logo.png +0 -0
- package/demo/test/local.json +0 -4
- package/demo/test3/image/logo.png +0 -0
- package/demo/test3/local.json +0 -4
- package/demo/test4/image/logo.png +0 -0
- package/demo/test4/local.json +0 -4
- package/demo/test5/local.json +0 -4
- package/demo/test5/local2.json +0 -4
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const JSON5 = require('json5');
|
|
7
7
|
var ncp = require('ncp').ncp;
|
|
8
|
+
const { rimraf, rimrafSync } = require('rimraf');
|
|
8
9
|
const {
|
|
9
10
|
j2xParser,
|
|
10
11
|
parse
|
|
@@ -17,7 +18,7 @@ const {
|
|
|
17
18
|
statSync,
|
|
18
19
|
readdirSync,
|
|
19
20
|
mkdirSync,
|
|
20
|
-
|
|
21
|
+
unlinkSync,
|
|
21
22
|
rmdir
|
|
22
23
|
} = require('fs');
|
|
23
24
|
const {
|
|
@@ -1356,10 +1357,10 @@ if (typeof($) === "undefined") {
|
|
|
1356
1357
|
|
|
1357
1358
|
/**
|
|
1358
1359
|
* @description 删除文件
|
|
1359
|
-
* @param {String}
|
|
1360
|
+
* @param {String} dir 当前路径
|
|
1360
1361
|
*/
|
|
1361
|
-
String.prototype.delFile = function(
|
|
1362
|
-
|
|
1362
|
+
String.prototype.delFile = function(dir) {
|
|
1363
|
+
unlinkSync(this.fullname(dir), function(e) {});
|
|
1363
1364
|
};
|
|
1364
1365
|
|
|
1365
1366
|
/**
|
|
@@ -1374,9 +1375,10 @@ if (typeof($) === "undefined") {
|
|
|
1374
1375
|
/**
|
|
1375
1376
|
* @description 删除目录
|
|
1376
1377
|
* @param {String} dir 当前路径
|
|
1378
|
+
* @param {Function} func 回调函数
|
|
1377
1379
|
*/
|
|
1378
|
-
String.prototype.delDir = function(dir) {
|
|
1379
|
-
|
|
1380
|
+
String.prototype.delDir = function(dir, func) {
|
|
1381
|
+
rimrafSync(this.fullname(dir), func);
|
|
1380
1382
|
};
|
|
1381
1383
|
|
|
1382
1384
|
/**
|
|
@@ -2130,6 +2132,32 @@ if (typeof($) === "undefined") {
|
|
|
2130
2132
|
});
|
|
2131
2133
|
return obj;
|
|
2132
2134
|
};
|
|
2135
|
+
|
|
2136
|
+
/**
|
|
2137
|
+
* 将一维数组转成二维
|
|
2138
|
+
* @param {Object} size
|
|
2139
|
+
*/
|
|
2140
|
+
Array.prototype.to2D = function(size) {
|
|
2141
|
+
var arr = this;
|
|
2142
|
+
let newArr = [];
|
|
2143
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
2144
|
+
let arrayChunk = arr.slice(i, i + size);
|
|
2145
|
+
newArr.push(arrayChunk);
|
|
2146
|
+
}
|
|
2147
|
+
return newArr;
|
|
2148
|
+
};
|
|
2149
|
+
|
|
2150
|
+
/**
|
|
2151
|
+
* 将二维数组合并转成一维
|
|
2152
|
+
*/
|
|
2153
|
+
Array.prototype.to1D = function() {
|
|
2154
|
+
var arr = this;
|
|
2155
|
+
let newArr = [];
|
|
2156
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2157
|
+
newArr = newArr.concat(arr[i]);
|
|
2158
|
+
}
|
|
2159
|
+
return newArr;
|
|
2160
|
+
};
|
|
2133
2161
|
})();
|
|
2134
2162
|
|
|
2135
2163
|
/**
|
|
@@ -2269,10 +2297,20 @@ if (typeof($) === "undefined") {
|
|
|
2269
2297
|
* 复制目录
|
|
2270
2298
|
* @param {String} sourcePath 源路径
|
|
2271
2299
|
* @param {String} targetPath 目标路径
|
|
2300
|
+
* @param {Function} func 回调函数
|
|
2272
2301
|
*/
|
|
2273
2302
|
Dir.prototype.copy = function(sourcePath, targetPath, func) {
|
|
2274
2303
|
ncp(sourcePath.fullname(), targetPath.fullname(), func);
|
|
2275
2304
|
}
|
|
2305
|
+
/**
|
|
2306
|
+
* @description 删除目录
|
|
2307
|
+
* @param {String} dir 目录路径
|
|
2308
|
+
* @param {Function} func 回调函数
|
|
2309
|
+
* @return {Boolean} 保存成功返回true,否则返回false
|
|
2310
|
+
*/
|
|
2311
|
+
Dir.prototype.del = function(dir, func) {
|
|
2312
|
+
rimrafSync(dir.fullname(), func);
|
|
2313
|
+
}
|
|
2276
2314
|
}
|
|
2277
2315
|
/**
|
|
2278
2316
|
* 文件类函数
|
|
@@ -2340,8 +2378,8 @@ if (typeof($) === "undefined") {
|
|
|
2340
2378
|
}
|
|
2341
2379
|
/**
|
|
2342
2380
|
* @description 加载文件
|
|
2343
|
-
* @param {String}
|
|
2344
|
-
* @param {String}
|
|
2381
|
+
* @param {String} sourcePath 文件原路径
|
|
2382
|
+
* @param {String} targetPath 目标路径
|
|
2345
2383
|
* @return {Boolean} 保存成功返回true,否则返回false
|
|
2346
2384
|
*/
|
|
2347
2385
|
File.prototype.copy = function(sourcePath, targetPath) {
|
|
@@ -2351,6 +2389,18 @@ if (typeof($) === "undefined") {
|
|
|
2351
2389
|
console.error(err);
|
|
2352
2390
|
}
|
|
2353
2391
|
}
|
|
2392
|
+
/**
|
|
2393
|
+
* @description 删除文件
|
|
2394
|
+
* @param {String} file 文件路径
|
|
2395
|
+
* @return {Boolean} 保存成功返回true,否则返回false
|
|
2396
|
+
*/
|
|
2397
|
+
File.prototype.del = function(file) {
|
|
2398
|
+
try {
|
|
2399
|
+
unlinkSync(file.fullname());
|
|
2400
|
+
} catch (err) {
|
|
2401
|
+
console.error(err);
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2354
2404
|
}
|
|
2355
2405
|
$.file = new File();
|
|
2356
2406
|
$.dir = new Dir();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.9",
|
|
4
4
|
"description": "这是超级美眉原型函数拓展模块,更有利于对string、array、object的操作,避免出错,简化业务逻辑。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"fast-xml-parser": "^3.21.1",
|
|
33
33
|
"json5": "^2.2.3",
|
|
34
34
|
"ncp": "^2.0.0",
|
|
35
|
-
"pinyinlite": "^1.2.1"
|
|
35
|
+
"pinyinlite": "^1.2.1",
|
|
36
|
+
"rimraf": "^5.0.5"
|
|
36
37
|
}
|
|
37
38
|
}
|
package/test.js
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
require('./index.js');
|
|
2
2
|
|
|
3
|
+
var arr1 = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
|
|
4
|
+
// var arr1 = [{
|
|
5
|
+
// id: 1
|
|
6
|
+
// }, {
|
|
7
|
+
// id: 2
|
|
8
|
+
// }, {
|
|
9
|
+
// id: 3
|
|
10
|
+
// }, '4', '5', '6', '7', '8', '9', '10', '11', '12'];
|
|
11
|
+
console.log('拆分', arr1.to2D(2));
|
|
12
|
+
console.log('拆分', arr1.to2D(3));
|
|
13
|
+
console.log('拆分', arr1.to2D(4));
|
|
14
|
+
console.log('拆分', arr1.to2D(5));
|
|
15
|
+
console.log('拆分', arr1.to2D(6));
|
|
16
|
+
console.log('拆分', arr1.to2D(7));
|
|
17
|
+
console.log('拆分', arr1.to2D(8));
|
|
18
|
+
|
|
19
|
+
console.log('合并', arr1.to2D(7).to1D());
|
|
20
|
+
console.log('合并', arr1.to2D(8).to1D());
|
|
21
|
+
|
|
3
22
|
// 测试复制目录
|
|
23
|
+
// "./demo/test3".delDir();
|
|
24
|
+
// $.dir.del("./demo/test4");
|
|
4
25
|
// "./demo/test".copyDir("./demo/test3"); // 方法1
|
|
5
26
|
// $.dir.copy("./demo/test", "./demo/test4"); // 方法2
|
|
6
27
|
|
|
7
|
-
// 测试复制文件
|
|
8
|
-
"./demo/test5/".addDir();
|
|
9
|
-
"./demo/test/local.json".
|
|
10
|
-
$.
|
|
28
|
+
// // 测试复制文件
|
|
29
|
+
// "./demo/test5/".addDir();
|
|
30
|
+
// "./demo/test/local.json".copyFile("./demo/test5/local.json"); // 方法1
|
|
31
|
+
// $.file.copy("./demo/test/local.json", "./demo/test5/local2.json"); // 方法2
|
|
32
|
+
// "./demo/test5/local.json".delFile();
|
|
33
|
+
// $.file.del("./demo/test5/local2.json");
|
|
11
34
|
|
|
12
35
|
// var timeStr = "1970-01-01 00:00:00";
|
|
13
36
|
|
package/demo/test/image/logo.png
DELETED
|
Binary file
|
package/demo/test/local.json
DELETED
|
Binary file
|
package/demo/test3/local.json
DELETED
|
Binary file
|
package/demo/test4/local.json
DELETED
package/demo/test5/local.json
DELETED
package/demo/test5/local2.json
DELETED