mm_expand 1.5.8 → 1.6.0
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 +44 -16
- package/package.json +1 -1
- package/test.js +46 -8
package/index.js
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const JSON5 = require('json5');
|
|
7
7
|
var ncp = require('ncp').ncp;
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
rimraf,
|
|
10
|
+
rimrafSync
|
|
11
|
+
} = require('rimraf');
|
|
9
12
|
const {
|
|
10
13
|
j2xParser,
|
|
11
14
|
parse
|
|
@@ -1235,23 +1238,22 @@ if (typeof($) === "undefined") {
|
|
|
1235
1238
|
*/
|
|
1236
1239
|
String.prototype.fullname = function(dir) {
|
|
1237
1240
|
var file = this + '';
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
file = file.replace('.' + slash, dir.fullname());
|
|
1242
|
-
} else {
|
|
1243
|
-
file = file.replace('.' + slash, $.runPath);
|
|
1241
|
+
if (dir) {
|
|
1242
|
+
if (!dir.endsWith(slash)) {
|
|
1243
|
+
dir += slash;
|
|
1244
1244
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1245
|
+
dir = dir.fullname();
|
|
1246
|
+
} else {
|
|
1247
|
+
dir = $.runPath;
|
|
1248
|
+
}
|
|
1249
|
+
file = file.replace(/\//g, slash);
|
|
1250
|
+
if (!file.startWith($.runPath)) {
|
|
1251
|
+
if (file.startWith(slash)) {
|
|
1252
|
+
file = join($.runPath, file);
|
|
1248
1253
|
} else {
|
|
1249
|
-
file =
|
|
1254
|
+
file = join(dir, file);
|
|
1250
1255
|
}
|
|
1251
|
-
} else if (file.startWith(slash) && !file.startWith($.runPath)) {
|
|
1252
|
-
file = $.runPath + file.substring(0);
|
|
1253
1256
|
}
|
|
1254
|
-
file = join(file, '');
|
|
1255
1257
|
if (file.indexOf('.') === -1 && !file.endsWith(slash)) {
|
|
1256
1258
|
file += slash;
|
|
1257
1259
|
}
|
|
@@ -1387,7 +1389,7 @@ if (typeof($) === "undefined") {
|
|
|
1387
1389
|
*/
|
|
1388
1390
|
String.prototype.addDir = function(dirbase) {
|
|
1389
1391
|
var d = (this + '').fullname(dirbase);
|
|
1390
|
-
|
|
1392
|
+
|
|
1391
1393
|
if (d.indexOf('.') !== -1) {
|
|
1392
1394
|
d = d.dirname()
|
|
1393
1395
|
}
|
|
@@ -1409,7 +1411,7 @@ if (typeof($) === "undefined") {
|
|
|
1409
1411
|
String.prototype.copyFile = function(file) {
|
|
1410
1412
|
return copyFileSync(this.fullname(), file.fullname());
|
|
1411
1413
|
};
|
|
1412
|
-
|
|
1414
|
+
|
|
1413
1415
|
/**
|
|
1414
1416
|
* @description 复制目录
|
|
1415
1417
|
* @param {String} file 保存路径
|
|
@@ -2132,6 +2134,32 @@ if (typeof($) === "undefined") {
|
|
|
2132
2134
|
});
|
|
2133
2135
|
return obj;
|
|
2134
2136
|
};
|
|
2137
|
+
|
|
2138
|
+
/**
|
|
2139
|
+
* 将一维数组转成二维
|
|
2140
|
+
* @param {Object} size
|
|
2141
|
+
*/
|
|
2142
|
+
Array.prototype.to2D = function(size) {
|
|
2143
|
+
var arr = this;
|
|
2144
|
+
let newArr = [];
|
|
2145
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
2146
|
+
let arrayChunk = arr.slice(i, i + size);
|
|
2147
|
+
newArr.push(arrayChunk);
|
|
2148
|
+
}
|
|
2149
|
+
return newArr;
|
|
2150
|
+
};
|
|
2151
|
+
|
|
2152
|
+
/**
|
|
2153
|
+
* 将二维数组合并转成一维
|
|
2154
|
+
*/
|
|
2155
|
+
Array.prototype.to1D = function() {
|
|
2156
|
+
var arr = this;
|
|
2157
|
+
let newArr = [];
|
|
2158
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2159
|
+
newArr = newArr.concat(arr[i]);
|
|
2160
|
+
}
|
|
2161
|
+
return newArr;
|
|
2162
|
+
};
|
|
2135
2163
|
})();
|
|
2136
2164
|
|
|
2137
2165
|
/**
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -1,17 +1,55 @@
|
|
|
1
1
|
require('./index.js');
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
console.log("./fast/log".fullname(__dirname));
|
|
5
|
+
console.log("./fast/log".fullname());
|
|
6
|
+
console.log("./fast/log/".fullname());
|
|
7
|
+
console.log("fast/log".fullname(__dirname));
|
|
8
|
+
console.log("fast/log".fullname());
|
|
9
|
+
console.log("fast/log/".fullname());
|
|
10
|
+
console.log("../fast/log".fullname(__dirname));
|
|
11
|
+
console.log("../fast/log".fullname());
|
|
12
|
+
console.log("/fast/log".fullname(__dirname));
|
|
13
|
+
console.log("/fast/log".fullname());
|
|
14
|
+
console.log("/fast/log/".fullname());
|
|
15
|
+
console.log("/fast/log.lgo".fullname());
|
|
16
|
+
console.log("/fast/log.lgo\\".fullname());
|
|
17
|
+
console.log("/fast/log.lgo/".fullname());
|
|
18
|
+
console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log\\".fullname(__dirname));
|
|
19
|
+
console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log\\".fullname());
|
|
20
|
+
console.log("E:\\github\\mm_modules\\mm_expand\\fast\\log".fullname());
|
|
21
|
+
// var arr1 = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
|
|
22
|
+
|
|
23
|
+
// var arr1 = [{
|
|
24
|
+
// id: 1
|
|
25
|
+
// }, {
|
|
26
|
+
// id: 2
|
|
27
|
+
// }, {
|
|
28
|
+
// id: 3
|
|
29
|
+
// }, '4', '5', '6', '7', '8', '9', '10', '11', '12'];
|
|
30
|
+
// console.log('拆分', arr1.to2D(2));
|
|
31
|
+
// console.log('拆分', arr1.to2D(3));
|
|
32
|
+
// console.log('拆分', arr1.to2D(4));
|
|
33
|
+
// console.log('拆分', arr1.to2D(5));
|
|
34
|
+
// console.log('拆分', arr1.to2D(6));
|
|
35
|
+
// console.log('拆分', arr1.to2D(7));
|
|
36
|
+
// console.log('拆分', arr1.to2D(8));
|
|
37
|
+
|
|
38
|
+
// console.log('合并', arr1.to2D(7).to1D());
|
|
39
|
+
// console.log('合并', arr1.to2D(8).to1D());
|
|
40
|
+
|
|
3
41
|
// 测试复制目录
|
|
4
|
-
"./demo/test3".delDir();
|
|
5
|
-
$.dir.del("./demo/test4");
|
|
42
|
+
// "./demo/test3".delDir();
|
|
43
|
+
// $.dir.del("./demo/test4");
|
|
6
44
|
// "./demo/test".copyDir("./demo/test3"); // 方法1
|
|
7
45
|
// $.dir.copy("./demo/test", "./demo/test4"); // 方法2
|
|
8
46
|
|
|
9
|
-
// 测试复制文件
|
|
10
|
-
"./demo/test5/".addDir();
|
|
11
|
-
"./demo/test/local.json".copyFile("./demo/test5/local.json"); // 方法1
|
|
12
|
-
$.file.copy("./demo/test/local.json", "./demo/test5/local2.json"); // 方法2
|
|
13
|
-
"./demo/test5/local.json".delFile();
|
|
14
|
-
$.file.del("./demo/test5/local2.json");
|
|
47
|
+
// // 测试复制文件
|
|
48
|
+
// "./demo/test5/".addDir();
|
|
49
|
+
// "./demo/test/local.json".copyFile("./demo/test5/local.json"); // 方法1
|
|
50
|
+
// $.file.copy("./demo/test/local.json", "./demo/test5/local2.json"); // 方法2
|
|
51
|
+
// "./demo/test5/local.json".delFile();
|
|
52
|
+
// $.file.del("./demo/test5/local2.json");
|
|
15
53
|
|
|
16
54
|
// var timeStr = "1970-01-01 00:00:00";
|
|
17
55
|
|