binary-collections 2.0.3 → 2.0.6
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/bin/bash-dummy +7 -2
- package/bin/clean-nodemodule +7 -2
- package/bin/clean-nodemodules +7 -2
- package/bin/dev +7 -2
- package/bin/empty +7 -2
- package/bin/git-fix-encoding +7 -2
- package/bin/git-reduce-size +7 -2
- package/bin/kill-process +7 -2
- package/bin/nodekill +7 -2
- package/bin/prod +7 -2
- package/bin/rmfind +7 -2
- package/bin/rmpath +7 -2
- package/bin/rmx +9 -3
- package/bin/submodule +13 -2
- package/bin/submodule-install +7 -2
- package/bin/submodule-remove +7 -2
- package/eslint.config.cjs +97 -0
- package/lib/chunk-7MSZ52XC.mjs +14 -0
- package/lib/chunk-AVDT32AY.mjs +20 -0
- package/lib/chunk-E75HJFJO.mjs +20 -0
- package/lib/chunk-GA4DDV65.mjs +202 -0
- package/lib/chunk-LPLPQBYP.mjs +53 -0
- package/lib/chunk-M4IBUK4H.mjs +173 -0
- package/lib/chunk-S4SJ7SDW.mjs +625 -0
- package/lib/del-gradle.cjs +72 -0
- package/lib/del-gradle.d.mts +2 -0
- package/lib/del-gradle.d.ts +2 -0
- package/lib/del-gradle.js +72 -0
- package/lib/del-gradle.mjs +28 -0
- package/lib/del-node-modules.cjs +72 -0
- package/lib/del-node-modules.d.mts +2 -0
- package/lib/del-node-modules.d.ts +2 -0
- package/lib/del-node-modules.js +72 -0
- package/lib/del-node-modules.mjs +28 -0
- package/lib/del-ps.cjs +706 -0
- package/lib/del-ps.d.mts +2 -0
- package/lib/del-ps.d.ts +2 -0
- package/lib/del-ps.js +706 -0
- package/lib/del-ps.mjs +46 -0
- package/lib/del-yarn-caches.cjs +65 -0
- package/lib/del-yarn-caches.d.mts +2 -0
- package/lib/del-yarn-caches.d.ts +2 -0
- package/lib/del-yarn-caches.js +65 -0
- package/lib/del-yarn-caches.mjs +21 -0
- package/lib/find-node-modules.cjs +12 -0
- package/lib/find-node-modules.d.mts +2 -0
- package/lib/find-node-modules.d.ts +2 -0
- package/lib/find-node-modules.js +6 -7
- package/lib/find-node-modules.mjs +21 -0
- package/lib/git-purge.cjs +704 -0
- package/lib/git-purge.d.mts +2 -0
- package/lib/git-purge.d.ts +2 -0
- package/lib/git-purge.js +704 -0
- package/lib/git-purge.mjs +50 -0
- package/lib/index.cjs +2 -0
- package/lib/index.d.mts +2 -0
- package/lib/index.d.ts +2 -0
- package/{index.js → lib/index.js} +1 -0
- package/lib/index.mjs +9 -0
- package/lib/npm-run-series.cjs +61 -0
- package/lib/npm-run-series.d.mts +1 -0
- package/lib/npm-run-series.d.ts +1 -0
- package/lib/npm-run-series.js +37 -20
- package/lib/npm-run-series.mjs +47 -0
- package/lib/package-resolutions.cjs +28 -0
- package/lib/package-resolutions.d.mts +25 -0
- package/lib/package-resolutions.d.ts +25 -0
- package/lib/package-resolutions.js +28 -0
- package/lib/package-resolutions.mjs +31 -0
- package/lib/ps/connected-domain.cjs +156 -0
- package/lib/ps/connected-domain.d.mts +3 -0
- package/lib/ps/connected-domain.d.ts +3 -0
- package/lib/ps/connected-domain.js +156 -0
- package/lib/ps/connected-domain.mjs +7 -0
- package/lib/ps/index.cjs +555 -0
- package/lib/ps/index.d.cjs +17 -0
- package/lib/ps/index.d.d.mts +26 -0
- package/lib/ps/index.d.d.ts +26 -0
- package/lib/ps/index.d.js +17 -0
- package/lib/ps/index.d.mjs +8 -0
- package/lib/ps/index.d.mts +26 -0
- package/lib/ps/index.d.ts +26 -0
- package/lib/ps/index.js +555 -0
- package/lib/ps/index.mjs +203 -0
- package/lib/ps/isWin.cjs +3 -0
- package/lib/ps/isWin.d.mts +3 -0
- package/lib/ps/isWin.d.ts +3 -0
- package/lib/ps/isWin.js +3 -0
- package/lib/ps/isWin.mjs +7 -0
- package/lib/ps/table-parser.cjs +359 -0
- package/lib/ps/table-parser.d.mts +3 -0
- package/lib/ps/table-parser.d.ts +3 -0
- package/lib/ps/table-parser.js +359 -0
- package/lib/ps/table-parser.mjs +8 -0
- package/lib/utils.cjs +35 -0
- package/lib/utils.d.mts +20 -0
- package/lib/utils.d.ts +20 -0
- package/lib/utils.js +35 -0
- package/lib/utils.mjs +7 -0
- package/package.json +89 -32
- package/readme.md +41 -0
- package/src/ps/index.js +285 -0
- package/test/package.json +19 -0
- package/lib/del-nodemodules.js +0 -52
- package/lib/package-resolutions.json +0 -22
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// src/ps/connected-domain.js
|
|
2
|
+
module.exports = function(tdArray, indicator, hardlink) {
|
|
3
|
+
hardlink = hardlink || false;
|
|
4
|
+
if (!tdArray) {
|
|
5
|
+
throw new Error("tdArray must be provided");
|
|
6
|
+
}
|
|
7
|
+
if (!indicator) {
|
|
8
|
+
throw new Error("indicator must be provided");
|
|
9
|
+
}
|
|
10
|
+
tdArray = JSON.parse(JSON.stringify(tdArray));
|
|
11
|
+
var domains = {};
|
|
12
|
+
var domainUUID = 0;
|
|
13
|
+
var pointsHash = {};
|
|
14
|
+
tdArray.forEach(function(row, y) {
|
|
15
|
+
row.forEach(function(colItem, x) {
|
|
16
|
+
var identifier2 = indicator(colItem, x, y);
|
|
17
|
+
var neighbours = [];
|
|
18
|
+
if (tdArray[y - 1] && tdArray[y - 1][x] !== void 0) {
|
|
19
|
+
neighbours.push(pointsHash[x + "_" + (y - 1)]);
|
|
20
|
+
}
|
|
21
|
+
if (row[x - 1] !== void 0) {
|
|
22
|
+
neighbours.push(pointsHash[x - 1 + "_" + y]);
|
|
23
|
+
}
|
|
24
|
+
if (!hardlink) {
|
|
25
|
+
if (tdArray[y - 1] && tdArray[y - 1][x - 1] !== void 0) {
|
|
26
|
+
neighbours.push(pointsHash[x - 1 + "_" + (y - 1)]);
|
|
27
|
+
}
|
|
28
|
+
if (tdArray[y - 1] && tdArray[y - 1][x + 1] !== void 0) {
|
|
29
|
+
neighbours.push(pointsHash[x + 1 + "_" + (y - 1)]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (neighbours.length) {
|
|
33
|
+
var matched = false;
|
|
34
|
+
neighbours.forEach(function(neighbour) {
|
|
35
|
+
if (neighbour.identifier == identifier2) {
|
|
36
|
+
if (!matched) {
|
|
37
|
+
addPointToDomain(colItem, x, y, neighbour.domainId);
|
|
38
|
+
matched = true;
|
|
39
|
+
} else {
|
|
40
|
+
var colItemPoint = pointsHash[x + "_" + y];
|
|
41
|
+
if (neighbour.domainId != colItemPoint.domainId) {
|
|
42
|
+
mergeDomains(neighbour.domainId, colItemPoint.domainId);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (!matched) {
|
|
48
|
+
addNewDomain(colItem, x, y, identifier2);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
addNewDomain(colItem, x, y, identifier2);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
var result = {
|
|
56
|
+
domains: [],
|
|
57
|
+
totalDomains: 0,
|
|
58
|
+
groupByIdentifier: {},
|
|
59
|
+
totalIdentifiers: 0
|
|
60
|
+
};
|
|
61
|
+
var domainId = null;
|
|
62
|
+
var identifier = null;
|
|
63
|
+
var domain = null;
|
|
64
|
+
for (domainId in domains) {
|
|
65
|
+
domain = domains[domainId];
|
|
66
|
+
domain.bounding = calculateBounding(domain.points);
|
|
67
|
+
identifier = domain.identifier;
|
|
68
|
+
result.domains.push(domain);
|
|
69
|
+
result.totalDomains++;
|
|
70
|
+
if (!(identifier in result.groupByIdentifier)) {
|
|
71
|
+
result.groupByIdentifier[identifier] = [];
|
|
72
|
+
result.totalIdentifiers++;
|
|
73
|
+
}
|
|
74
|
+
result.groupByIdentifier[identifier].push(domain);
|
|
75
|
+
}
|
|
76
|
+
function calculateBounding(points) {
|
|
77
|
+
var minX = null;
|
|
78
|
+
var minY = null;
|
|
79
|
+
var maxX = null;
|
|
80
|
+
var maxY = null;
|
|
81
|
+
points.forEach(function(point) {
|
|
82
|
+
if (minX === null || point.x < minX) {
|
|
83
|
+
minX = point.x;
|
|
84
|
+
}
|
|
85
|
+
if (minY === null || point.y < minY) {
|
|
86
|
+
minY = point.y;
|
|
87
|
+
}
|
|
88
|
+
if (maxX === null || point.x > maxX) {
|
|
89
|
+
maxX = point.x;
|
|
90
|
+
}
|
|
91
|
+
if (maxY === null || point.y > maxY) {
|
|
92
|
+
maxY = point.y;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
var w = maxX - minX;
|
|
96
|
+
var h = maxY - minY;
|
|
97
|
+
return {
|
|
98
|
+
x: minX,
|
|
99
|
+
y: minY,
|
|
100
|
+
w,
|
|
101
|
+
h
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function addNewDomain(point, x, y, identifier2) {
|
|
105
|
+
var newDomain = {
|
|
106
|
+
identifier: identifier2,
|
|
107
|
+
domainId: ++domainUUID,
|
|
108
|
+
bounding: {},
|
|
109
|
+
points: []
|
|
110
|
+
};
|
|
111
|
+
var newPoint = {
|
|
112
|
+
value: point,
|
|
113
|
+
x,
|
|
114
|
+
y,
|
|
115
|
+
identifier: identifier2,
|
|
116
|
+
domainId: newDomain.domainId
|
|
117
|
+
};
|
|
118
|
+
pointsHash[x + "_" + y] = {
|
|
119
|
+
value: point,
|
|
120
|
+
identifier: identifier2,
|
|
121
|
+
domainId: newDomain.domainId
|
|
122
|
+
};
|
|
123
|
+
newDomain.points.push(newPoint);
|
|
124
|
+
domains[newDomain.domainId] = newDomain;
|
|
125
|
+
}
|
|
126
|
+
function addPointToDomain(point, x, y, domainId2) {
|
|
127
|
+
var domain2 = domains[domainId2];
|
|
128
|
+
var newPoint = {
|
|
129
|
+
value: point,
|
|
130
|
+
x,
|
|
131
|
+
y,
|
|
132
|
+
identifier: domain2.identifier,
|
|
133
|
+
domainId: domainId2
|
|
134
|
+
};
|
|
135
|
+
pointsHash[x + "_" + y] = {
|
|
136
|
+
value: point,
|
|
137
|
+
identifier: domain2.identifier,
|
|
138
|
+
domainId: domainId2
|
|
139
|
+
};
|
|
140
|
+
domain2.points.push(newPoint);
|
|
141
|
+
}
|
|
142
|
+
function mergeDomains(domainAId, domainBId) {
|
|
143
|
+
var domainA = domains[domainAId];
|
|
144
|
+
var domainB = domains[domainBId];
|
|
145
|
+
if (domainA.identifier == domainB.identifier) {
|
|
146
|
+
domainB.domainId = domainA.domainId;
|
|
147
|
+
domainB.points.forEach(function(point) {
|
|
148
|
+
point.domainId = domainA.domainId;
|
|
149
|
+
pointsHash[point.x + "_" + point.y].domainId = domainA.domainId;
|
|
150
|
+
});
|
|
151
|
+
domainA.points = domainA.points.concat(domainB.points);
|
|
152
|
+
delete domains[domainBId];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
require_connected_domain
|
|
4
|
+
} from "../chunk-M4IBUK4H.mjs";
|
|
5
|
+
import "../chunk-7MSZ52XC.mjs";
|
|
6
|
+
import "../chunk-AVDT32AY.mjs";
|
|
7
|
+
export default require_connected_domain();
|
package/lib/ps/index.cjs
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __esm = (fn, res) => function __init() {
|
|
3
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
4
|
+
};
|
|
5
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
6
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
10
|
+
var init_cjs_shims = __esm({
|
|
11
|
+
"node_modules/tsup/assets/cjs_shims.js"() {
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// src/ps/isWin.js
|
|
16
|
+
var require_isWin = __commonJS({
|
|
17
|
+
"src/ps/isWin.js"(exports2, module2) {
|
|
18
|
+
init_cjs_shims();
|
|
19
|
+
var isWin = process.platform === "win32";
|
|
20
|
+
module2.exports = isWin;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// src/ps/connected-domain.js
|
|
25
|
+
var require_connected_domain = __commonJS({
|
|
26
|
+
"src/ps/connected-domain.js"(exports2, module2) {
|
|
27
|
+
init_cjs_shims();
|
|
28
|
+
module2.exports = function(tdArray, indicator, hardlink) {
|
|
29
|
+
hardlink = hardlink || false;
|
|
30
|
+
if (!tdArray) {
|
|
31
|
+
throw new Error("tdArray must be provided");
|
|
32
|
+
}
|
|
33
|
+
if (!indicator) {
|
|
34
|
+
throw new Error("indicator must be provided");
|
|
35
|
+
}
|
|
36
|
+
tdArray = JSON.parse(JSON.stringify(tdArray));
|
|
37
|
+
var domains = {};
|
|
38
|
+
var domainUUID = 0;
|
|
39
|
+
var pointsHash = {};
|
|
40
|
+
tdArray.forEach(function(row, y) {
|
|
41
|
+
row.forEach(function(colItem, x) {
|
|
42
|
+
var identifier2 = indicator(colItem, x, y);
|
|
43
|
+
var neighbours = [];
|
|
44
|
+
if (tdArray[y - 1] && tdArray[y - 1][x] !== void 0) {
|
|
45
|
+
neighbours.push(pointsHash[x + "_" + (y - 1)]);
|
|
46
|
+
}
|
|
47
|
+
if (row[x - 1] !== void 0) {
|
|
48
|
+
neighbours.push(pointsHash[x - 1 + "_" + y]);
|
|
49
|
+
}
|
|
50
|
+
if (!hardlink) {
|
|
51
|
+
if (tdArray[y - 1] && tdArray[y - 1][x - 1] !== void 0) {
|
|
52
|
+
neighbours.push(pointsHash[x - 1 + "_" + (y - 1)]);
|
|
53
|
+
}
|
|
54
|
+
if (tdArray[y - 1] && tdArray[y - 1][x + 1] !== void 0) {
|
|
55
|
+
neighbours.push(pointsHash[x + 1 + "_" + (y - 1)]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (neighbours.length) {
|
|
59
|
+
var matched = false;
|
|
60
|
+
neighbours.forEach(function(neighbour) {
|
|
61
|
+
if (neighbour.identifier == identifier2) {
|
|
62
|
+
if (!matched) {
|
|
63
|
+
addPointToDomain(colItem, x, y, neighbour.domainId);
|
|
64
|
+
matched = true;
|
|
65
|
+
} else {
|
|
66
|
+
var colItemPoint = pointsHash[x + "_" + y];
|
|
67
|
+
if (neighbour.domainId != colItemPoint.domainId) {
|
|
68
|
+
mergeDomains(neighbour.domainId, colItemPoint.domainId);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
if (!matched) {
|
|
74
|
+
addNewDomain(colItem, x, y, identifier2);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
addNewDomain(colItem, x, y, identifier2);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
var result = {
|
|
82
|
+
domains: [],
|
|
83
|
+
totalDomains: 0,
|
|
84
|
+
groupByIdentifier: {},
|
|
85
|
+
totalIdentifiers: 0
|
|
86
|
+
};
|
|
87
|
+
var domainId = null;
|
|
88
|
+
var identifier = null;
|
|
89
|
+
var domain = null;
|
|
90
|
+
for (domainId in domains) {
|
|
91
|
+
domain = domains[domainId];
|
|
92
|
+
domain.bounding = calculateBounding(domain.points);
|
|
93
|
+
identifier = domain.identifier;
|
|
94
|
+
result.domains.push(domain);
|
|
95
|
+
result.totalDomains++;
|
|
96
|
+
if (!(identifier in result.groupByIdentifier)) {
|
|
97
|
+
result.groupByIdentifier[identifier] = [];
|
|
98
|
+
result.totalIdentifiers++;
|
|
99
|
+
}
|
|
100
|
+
result.groupByIdentifier[identifier].push(domain);
|
|
101
|
+
}
|
|
102
|
+
function calculateBounding(points) {
|
|
103
|
+
var minX = null;
|
|
104
|
+
var minY = null;
|
|
105
|
+
var maxX = null;
|
|
106
|
+
var maxY = null;
|
|
107
|
+
points.forEach(function(point) {
|
|
108
|
+
if (minX === null || point.x < minX) {
|
|
109
|
+
minX = point.x;
|
|
110
|
+
}
|
|
111
|
+
if (minY === null || point.y < minY) {
|
|
112
|
+
minY = point.y;
|
|
113
|
+
}
|
|
114
|
+
if (maxX === null || point.x > maxX) {
|
|
115
|
+
maxX = point.x;
|
|
116
|
+
}
|
|
117
|
+
if (maxY === null || point.y > maxY) {
|
|
118
|
+
maxY = point.y;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
var w = maxX - minX;
|
|
122
|
+
var h = maxY - minY;
|
|
123
|
+
return {
|
|
124
|
+
x: minX,
|
|
125
|
+
y: minY,
|
|
126
|
+
w,
|
|
127
|
+
h
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function addNewDomain(point, x, y, identifier2) {
|
|
131
|
+
var newDomain = {
|
|
132
|
+
identifier: identifier2,
|
|
133
|
+
domainId: ++domainUUID,
|
|
134
|
+
bounding: {},
|
|
135
|
+
points: []
|
|
136
|
+
};
|
|
137
|
+
var newPoint = {
|
|
138
|
+
value: point,
|
|
139
|
+
x,
|
|
140
|
+
y,
|
|
141
|
+
identifier: identifier2,
|
|
142
|
+
domainId: newDomain.domainId
|
|
143
|
+
};
|
|
144
|
+
pointsHash[x + "_" + y] = {
|
|
145
|
+
value: point,
|
|
146
|
+
identifier: identifier2,
|
|
147
|
+
domainId: newDomain.domainId
|
|
148
|
+
};
|
|
149
|
+
newDomain.points.push(newPoint);
|
|
150
|
+
domains[newDomain.domainId] = newDomain;
|
|
151
|
+
}
|
|
152
|
+
function addPointToDomain(point, x, y, domainId2) {
|
|
153
|
+
var domain2 = domains[domainId2];
|
|
154
|
+
var newPoint = {
|
|
155
|
+
value: point,
|
|
156
|
+
x,
|
|
157
|
+
y,
|
|
158
|
+
identifier: domain2.identifier,
|
|
159
|
+
domainId: domainId2
|
|
160
|
+
};
|
|
161
|
+
pointsHash[x + "_" + y] = {
|
|
162
|
+
value: point,
|
|
163
|
+
identifier: domain2.identifier,
|
|
164
|
+
domainId: domainId2
|
|
165
|
+
};
|
|
166
|
+
domain2.points.push(newPoint);
|
|
167
|
+
}
|
|
168
|
+
function mergeDomains(domainAId, domainBId) {
|
|
169
|
+
var domainA = domains[domainAId];
|
|
170
|
+
var domainB = domains[domainBId];
|
|
171
|
+
if (domainA.identifier == domainB.identifier) {
|
|
172
|
+
domainB.domainId = domainA.domainId;
|
|
173
|
+
domainB.points.forEach(function(point) {
|
|
174
|
+
point.domainId = domainA.domainId;
|
|
175
|
+
pointsHash[point.x + "_" + point.y].domainId = domainA.domainId;
|
|
176
|
+
});
|
|
177
|
+
domainA.points = domainA.points.concat(domainB.points);
|
|
178
|
+
delete domains[domainBId];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// src/ps/table-parser.js
|
|
187
|
+
var require_table_parser = __commonJS({
|
|
188
|
+
"src/ps/table-parser.js"(exports2, module2) {
|
|
189
|
+
init_cjs_shims();
|
|
190
|
+
var ConnectedDomain = require_connected_domain();
|
|
191
|
+
var EMPTY_EX = /\s/;
|
|
192
|
+
module2.exports.parse = function(output) {
|
|
193
|
+
var linesTmp = output.split(/(\r\n)|(\n\r)|\n|\r/);
|
|
194
|
+
var lines = [];
|
|
195
|
+
var titleInfo = {};
|
|
196
|
+
var twoDimArray = [];
|
|
197
|
+
linesTmp.forEach(function(line) {
|
|
198
|
+
if (line && line.trim()) {
|
|
199
|
+
lines.push(line);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
lines.forEach(function(line, index) {
|
|
203
|
+
if (index == 0) {
|
|
204
|
+
var fields = line.split(/\s+/);
|
|
205
|
+
var currentIndex = 0;
|
|
206
|
+
fields.forEach(function(field, idx) {
|
|
207
|
+
if (field) {
|
|
208
|
+
var info = titleInfo[field] = {};
|
|
209
|
+
var indexBegin = line.indexOf(field, currentIndex);
|
|
210
|
+
var indexEnd = currentIndex = indexBegin + field.length;
|
|
211
|
+
if (idx == 0) {
|
|
212
|
+
info.titleBegin = 0;
|
|
213
|
+
} else {
|
|
214
|
+
info.titleBegin = indexBegin;
|
|
215
|
+
}
|
|
216
|
+
if (idx == fields.length - 1) {
|
|
217
|
+
info.titleEnd = line.length - 1;
|
|
218
|
+
} else {
|
|
219
|
+
info.titleEnd = indexEnd;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
twoDimArray[index - 1] = line.split("");
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
var connectedDomains = ConnectedDomain(
|
|
228
|
+
twoDimArray,
|
|
229
|
+
function(value) {
|
|
230
|
+
if (EMPTY_EX.test(value)) {
|
|
231
|
+
return -1;
|
|
232
|
+
} else {
|
|
233
|
+
return 1;
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
true
|
|
237
|
+
);
|
|
238
|
+
var valuesDomainsVerticalGroups = [];
|
|
239
|
+
connectedDomains.domains.sort(function(a, b) {
|
|
240
|
+
return a.bounding.x - b.bounding.x;
|
|
241
|
+
});
|
|
242
|
+
connectedDomains.domains.forEach(function(domain) {
|
|
243
|
+
if (domain.identifier === 1) {
|
|
244
|
+
var overlapped = false;
|
|
245
|
+
valuesDomainsVerticalGroups.forEach(function(group) {
|
|
246
|
+
var bounding = domain.bounding;
|
|
247
|
+
var left = bounding.x;
|
|
248
|
+
var right = bounding.x + bounding.w;
|
|
249
|
+
if (overlap(left, right, group.begin, group.end)) {
|
|
250
|
+
overlapped = true;
|
|
251
|
+
group.domains.push(domain);
|
|
252
|
+
group.begin = group.begin > left ? left : group.begin;
|
|
253
|
+
group.end = group.end < right ? right : group.end;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
if (!overlapped) {
|
|
257
|
+
valuesDomainsVerticalGroups.push({
|
|
258
|
+
begin: domain.bounding.x,
|
|
259
|
+
end: domain.bounding.x + domain.bounding.w,
|
|
260
|
+
domains: [domain]
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
valuesDomainsVerticalGroups.forEach(function(group) {
|
|
266
|
+
var title = null;
|
|
267
|
+
var info = null;
|
|
268
|
+
var overlapped = false;
|
|
269
|
+
var minimunLeftDistance = null;
|
|
270
|
+
var nearestLeftTitle = null;
|
|
271
|
+
var distance = null;
|
|
272
|
+
for (title in titleInfo) {
|
|
273
|
+
info = titleInfo[title];
|
|
274
|
+
if (group.begin > info.titleBegin) {
|
|
275
|
+
distance = group.begin - info.titleBegin;
|
|
276
|
+
if (!nearestLeftTitle || distance < minimunLeftDistance) {
|
|
277
|
+
nearestLeftTitle = title;
|
|
278
|
+
minimunLeftDistance = distance;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (overlap(group.begin, group.end, info.titleBegin, info.titleEnd)) {
|
|
282
|
+
overlapped = true;
|
|
283
|
+
info.titleBegin = info.titleBegin > group.begin ? group.begin : info.titleBegin;
|
|
284
|
+
info.titleEnd = info.titleEnd < group.end ? group.end : info.titleEnd;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (!overlapped && nearestLeftTitle) {
|
|
288
|
+
var nearestTitleField = titleInfo[nearestLeftTitle];
|
|
289
|
+
nearestTitleField.titleBegin = nearestTitleField.titleBegin > group.begin ? group.begin : nearestTitleField.titleBegin;
|
|
290
|
+
nearestTitleField.titleEnd = nearestTitleField.titleEnd < group.end ? group.end : nearestTitleField.titleEnd;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
var result = [];
|
|
294
|
+
lines.forEach(function(line, index) {
|
|
295
|
+
if (index > 0) {
|
|
296
|
+
var lineItem = {};
|
|
297
|
+
var title = null;
|
|
298
|
+
var info = null;
|
|
299
|
+
var value = null;
|
|
300
|
+
for (title in titleInfo) {
|
|
301
|
+
info = titleInfo[title];
|
|
302
|
+
value = line.substring(info.titleBegin, info.titleEnd + 1);
|
|
303
|
+
lineItem[title] = splitValue(value.trim());
|
|
304
|
+
}
|
|
305
|
+
result.push(lineItem);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
return result;
|
|
309
|
+
};
|
|
310
|
+
function overlap(begin1, end1, begin2, end2) {
|
|
311
|
+
return begin1 > begin2 && begin1 < end2 || // 2--1--2--1 or 2--1--1--2
|
|
312
|
+
end1 > begin2 && end1 < end2 || // 1--2--1--2 or 2--1--1--2
|
|
313
|
+
begin1 <= begin2 && end1 >= end2;
|
|
314
|
+
}
|
|
315
|
+
function splitValue(value) {
|
|
316
|
+
var match = value.match(/"/g);
|
|
317
|
+
if (!match || match.length == 1) {
|
|
318
|
+
return value.split(/\s+/);
|
|
319
|
+
} else {
|
|
320
|
+
var result = [];
|
|
321
|
+
var chunk = null;
|
|
322
|
+
var ifInWrappedChunk = false;
|
|
323
|
+
var ifInPureWrappedChunk = false;
|
|
324
|
+
var quotaCount = 0;
|
|
325
|
+
var maxQuotaCount = match.length % 2 == 0 ? match.length : match.length - 1;
|
|
326
|
+
var previousItem = null;
|
|
327
|
+
var values = value.split("");
|
|
328
|
+
values.forEach(function(item, index) {
|
|
329
|
+
if (item !== " ") {
|
|
330
|
+
if (item === '"') {
|
|
331
|
+
if (ifInWrappedChunk === false && quotaCount <= maxQuotaCount) {
|
|
332
|
+
ifInWrappedChunk = true;
|
|
333
|
+
quotaCount++;
|
|
334
|
+
if (previousItem === " " || previousItem === null) {
|
|
335
|
+
ifInPureWrappedChunk = true;
|
|
336
|
+
chunk = "";
|
|
337
|
+
} else {
|
|
338
|
+
chunk += item;
|
|
339
|
+
}
|
|
340
|
+
} else if (ifInWrappedChunk === true) {
|
|
341
|
+
ifInWrappedChunk = false;
|
|
342
|
+
quotaCount++;
|
|
343
|
+
if (ifInPureWrappedChunk === true) {
|
|
344
|
+
ifInPureWrappedChunk = false;
|
|
345
|
+
result.push(chunk);
|
|
346
|
+
chunk = null;
|
|
347
|
+
} else {
|
|
348
|
+
chunk += item;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} else if (ifInWrappedChunk === false && (previousItem === " " || previousItem === null)) {
|
|
352
|
+
chunk = item;
|
|
353
|
+
} else {
|
|
354
|
+
chunk += item;
|
|
355
|
+
}
|
|
356
|
+
} else if (ifInWrappedChunk) {
|
|
357
|
+
chunk += item;
|
|
358
|
+
} else if (chunk !== null) {
|
|
359
|
+
result.push(chunk);
|
|
360
|
+
chunk = null;
|
|
361
|
+
}
|
|
362
|
+
previousItem = item;
|
|
363
|
+
if (index == values.length - 1 && chunk !== null) {
|
|
364
|
+
result.push(chunk);
|
|
365
|
+
chunk = null;
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// src/ps/index.js
|
|
375
|
+
init_cjs_shims();
|
|
376
|
+
var ChildProcess = require("child_process");
|
|
377
|
+
var IS_WIN = require_isWin();
|
|
378
|
+
var TableParser = require_table_parser();
|
|
379
|
+
var EOL = /(\r\n)|(\n\r)|\n|\r/;
|
|
380
|
+
var SystemEOL = require("os").EOL;
|
|
381
|
+
var Exec = module.exports = exports = function(args, callback) {
|
|
382
|
+
var spawn = ChildProcess.spawn;
|
|
383
|
+
if (IS_WIN) {
|
|
384
|
+
var CMD = spawn("cmd");
|
|
385
|
+
var stdout = "";
|
|
386
|
+
var stderr = null;
|
|
387
|
+
CMD.stdout.on("data", function(data) {
|
|
388
|
+
stdout += data.toString();
|
|
389
|
+
});
|
|
390
|
+
CMD.stderr.on("data", function(data) {
|
|
391
|
+
if (stderr === null) {
|
|
392
|
+
stderr = data.toString();
|
|
393
|
+
} else {
|
|
394
|
+
stderr += data.toString();
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
CMD.on("exit", function() {
|
|
398
|
+
var beginRow;
|
|
399
|
+
stdout = stdout.split(EOL);
|
|
400
|
+
stdout.forEach(function(out, index) {
|
|
401
|
+
if (out && typeof beginRow == "undefined" && out.indexOf("CommandLine") === 0) {
|
|
402
|
+
beginRow = index;
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
stdout.splice(stdout.length - 1, 1);
|
|
406
|
+
stdout.splice(0, beginRow);
|
|
407
|
+
callback(stderr, stdout.join(SystemEOL) || false);
|
|
408
|
+
});
|
|
409
|
+
CMD.stdin.write("wmic process get ProcessId,ParentProcessId,CommandLine \n");
|
|
410
|
+
CMD.stdin.end();
|
|
411
|
+
} else {
|
|
412
|
+
if (typeof args === "string") {
|
|
413
|
+
args = args.split(/\s+/);
|
|
414
|
+
}
|
|
415
|
+
const child = spawn("ps", args);
|
|
416
|
+
stdout = "";
|
|
417
|
+
stderr = null;
|
|
418
|
+
child.stdout.on("data", function(data) {
|
|
419
|
+
stdout += data.toString();
|
|
420
|
+
});
|
|
421
|
+
child.stderr.on("data", function(data) {
|
|
422
|
+
if (stderr === null) {
|
|
423
|
+
stderr = data.toString();
|
|
424
|
+
} else {
|
|
425
|
+
stderr += data.toString();
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
child.on("exit", function() {
|
|
429
|
+
if (stderr) {
|
|
430
|
+
return callback(stderr.toString());
|
|
431
|
+
} else {
|
|
432
|
+
callback(null, stdout || false);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
exports.lookup = function(query, callback) {
|
|
438
|
+
var exeArgs = query.psargs || ["lx"];
|
|
439
|
+
var filter = {};
|
|
440
|
+
var idList;
|
|
441
|
+
if (query.pid) {
|
|
442
|
+
if (Array.isArray(query.pid)) {
|
|
443
|
+
idList = query.pid;
|
|
444
|
+
} else {
|
|
445
|
+
idList = [query.pid];
|
|
446
|
+
}
|
|
447
|
+
idList = idList.map(function(v) {
|
|
448
|
+
return String(v);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
if (query.command) {
|
|
452
|
+
filter["command"] = new RegExp(query.command, "i");
|
|
453
|
+
}
|
|
454
|
+
if (query.arguments) {
|
|
455
|
+
filter["arguments"] = new RegExp(query.arguments, "i");
|
|
456
|
+
}
|
|
457
|
+
if (query.ppid) {
|
|
458
|
+
filter["ppid"] = new RegExp(query.ppid);
|
|
459
|
+
}
|
|
460
|
+
return Exec(exeArgs, function(err, output) {
|
|
461
|
+
if (err) {
|
|
462
|
+
return callback(err);
|
|
463
|
+
} else {
|
|
464
|
+
var processList = parseGrid(output);
|
|
465
|
+
var resultList = [];
|
|
466
|
+
processList.forEach(function(p) {
|
|
467
|
+
var flt;
|
|
468
|
+
var type;
|
|
469
|
+
var result = true;
|
|
470
|
+
if (idList && idList.indexOf(String(p.pid)) < 0) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
for (type in filter) {
|
|
474
|
+
flt = filter[type];
|
|
475
|
+
result = flt.test(p[type]) ? result : false;
|
|
476
|
+
}
|
|
477
|
+
if (result) {
|
|
478
|
+
resultList.push(p);
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
callback(null, resultList);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
};
|
|
485
|
+
exports.kill = function(pid, signal, next) {
|
|
486
|
+
if (arguments.length == 2 && typeof signal == "function") {
|
|
487
|
+
next = signal;
|
|
488
|
+
signal = void 0;
|
|
489
|
+
}
|
|
490
|
+
var checkTimeoutSeconds = signal && signal.timeout || 30;
|
|
491
|
+
if (typeof signal === "object") {
|
|
492
|
+
signal = signal.signal;
|
|
493
|
+
}
|
|
494
|
+
try {
|
|
495
|
+
process.kill(pid, signal);
|
|
496
|
+
} catch (e) {
|
|
497
|
+
return next && next(e);
|
|
498
|
+
}
|
|
499
|
+
var checkConfident = 0;
|
|
500
|
+
var checkTimeoutTimer = null;
|
|
501
|
+
var checkIsTimeout = false;
|
|
502
|
+
function checkKilled(finishCallback) {
|
|
503
|
+
exports.lookup({ pid }, function(err, list) {
|
|
504
|
+
if (checkIsTimeout) return;
|
|
505
|
+
if (err) {
|
|
506
|
+
clearTimeout(checkTimeoutTimer);
|
|
507
|
+
finishCallback && finishCallback(err);
|
|
508
|
+
} else if (list.length > 0) {
|
|
509
|
+
checkConfident = checkConfident - 1 || 0;
|
|
510
|
+
checkKilled(finishCallback);
|
|
511
|
+
} else {
|
|
512
|
+
checkConfident++;
|
|
513
|
+
if (checkConfident === 5) {
|
|
514
|
+
clearTimeout(checkTimeoutTimer);
|
|
515
|
+
finishCallback && finishCallback();
|
|
516
|
+
} else {
|
|
517
|
+
checkKilled(finishCallback);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
next && checkKilled(next);
|
|
523
|
+
checkTimeoutTimer = next && setTimeout(function() {
|
|
524
|
+
checkIsTimeout = true;
|
|
525
|
+
next(new Error("Kill process timeout"));
|
|
526
|
+
}, checkTimeoutSeconds * 1e3);
|
|
527
|
+
};
|
|
528
|
+
function parseGrid(output) {
|
|
529
|
+
if (!output) {
|
|
530
|
+
return [];
|
|
531
|
+
}
|
|
532
|
+
return formatOutput(TableParser.parse(output));
|
|
533
|
+
}
|
|
534
|
+
function formatOutput(data) {
|
|
535
|
+
var formatedData = [];
|
|
536
|
+
data.forEach(function(d) {
|
|
537
|
+
var pid = d.PID && d.PID[0] || d.ProcessId && d.ProcessId[0] || void 0;
|
|
538
|
+
var cmd = d.CMD || d.CommandLine || d.COMMAND || void 0;
|
|
539
|
+
var ppid = d.PPID && d.PPID[0] || d.ParentProcessId && d.ParentProcessId[0] || void 0;
|
|
540
|
+
if (pid && cmd) {
|
|
541
|
+
var command = cmd[0];
|
|
542
|
+
var args = "";
|
|
543
|
+
if (cmd.length > 1) {
|
|
544
|
+
args = cmd.slice(1);
|
|
545
|
+
}
|
|
546
|
+
formatedData.push({
|
|
547
|
+
pid,
|
|
548
|
+
command,
|
|
549
|
+
arguments: args,
|
|
550
|
+
ppid
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
return formatedData;
|
|
555
|
+
}
|