mm_expand 1.5.9 → 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 +30 -28
- package/package.json +1 -1
- package/test.js +30 -11
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,31 +2134,31 @@ if (typeof($) === "undefined") {
|
|
|
2132
2134
|
});
|
|
2133
2135
|
return obj;
|
|
2134
2136
|
};
|
|
2135
|
-
|
|
2137
|
+
|
|
2136
2138
|
/**
|
|
2137
2139
|
* 将一维数组转成二维
|
|
2138
2140
|
* @param {Object} size
|
|
2139
2141
|
*/
|
|
2140
2142
|
Array.prototype.to2D = function(size) {
|
|
2141
2143
|
var arr = this;
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
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;
|
|
2148
2150
|
};
|
|
2149
|
-
|
|
2151
|
+
|
|
2150
2152
|
/**
|
|
2151
2153
|
* 将二维数组合并转成一维
|
|
2152
2154
|
*/
|
|
2153
2155
|
Array.prototype.to1D = function() {
|
|
2154
2156
|
var arr = this;
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
+
let newArr = [];
|
|
2158
|
+
for (let i = 0; i < arr.length; i++) {
|
|
2157
2159
|
newArr = newArr.concat(arr[i]);
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
+
}
|
|
2161
|
+
return newArr;
|
|
2160
2162
|
};
|
|
2161
2163
|
})();
|
|
2162
2164
|
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
require('./index.js');
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
|
|
4
23
|
// var arr1 = [{
|
|
5
24
|
// id: 1
|
|
6
25
|
// }, {
|
|
@@ -8,16 +27,16 @@ var arr1 = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
|
|
|
8
27
|
// }, {
|
|
9
28
|
// id: 3
|
|
10
29
|
// }, '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());
|
|
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());
|
|
21
40
|
|
|
22
41
|
// 测试复制目录
|
|
23
42
|
// "./demo/test3".delDir();
|