binary-collections 2.0.5 → 2.0.7
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-diff.cmd +4 -0
- package/bin/git-fix-encoding +7 -2
- package/bin/git-fix-encoding.cmd +0 -0
- package/bin/git-reduce-size +7 -2
- package/bin/kill-process +7 -2
- package/bin/nodekill +7 -2
- package/bin/nodekill.cmd +0 -0
- package/bin/nodekill.ps1 +0 -0
- 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/lib/chunk-3LOB2P54.mjs +202 -0
- package/lib/chunk-4LEXWIIF.mjs +173 -0
- package/lib/chunk-BSD5CIRU.mjs +52 -0
- package/lib/chunk-FB6YIQYR.mjs +42 -0
- package/lib/chunk-JL32QDSH.mjs +20 -0
- package/lib/chunk-OKYLF2MU.mjs +53 -0
- package/lib/chunk-VXZQNLPU.mjs +23 -0
- package/lib/del-gradle.cjs +72 -0
- package/lib/del-gradle.d.mts +2 -0
- package/lib/del-gradle.d.ts +1 -0
- package/lib/del-gradle.js +15 -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 +1 -0
- package/lib/del-node-modules.js +11 -15
- package/lib/del-node-modules.mjs +28 -0
- package/lib/del-ps.cjs +93 -0
- package/lib/del-ps.d.mts +2 -0
- package/lib/del-ps.d.ts +1 -0
- package/lib/del-ps.js +31 -0
- package/lib/del-ps.mjs +43 -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 +1 -0
- package/lib/del-yarn-caches.js +6 -9
- package/lib/del-yarn-caches.mjs +21 -0
- package/lib/find-node-modules-cli.cjs +59 -0
- package/lib/find-node-modules-cli.d.mts +1 -0
- package/lib/find-node-modules-cli.d.ts +2 -0
- package/lib/find-node-modules-cli.js +3 -0
- package/lib/find-node-modules-cli.mjs +14 -0
- package/lib/find-node-modules.cjs +34 -0
- package/lib/find-node-modules.d.mts +10 -0
- package/lib/find-node-modules.d.ts +9 -0
- package/lib/find-node-modules.js +41 -13
- package/lib/find-node-modules.mjs +7 -0
- package/lib/git-diff.cjs +74 -0
- package/lib/git-diff.d.cts +2 -0
- package/lib/git-diff.d.mts +87 -0
- package/lib/git-diff.d.ts +87 -0
- package/lib/git-diff.mjs +83 -0
- package/lib/git-purge.cjs +91 -0
- package/lib/git-purge.d.mts +2 -0
- package/lib/git-purge.d.ts +1 -0
- package/lib/git-purge.js +59 -0
- package/lib/git-purge.mjs +47 -0
- package/lib/index.cjs +92 -0
- package/lib/index.d.mts +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -0
- package/lib/index.mjs +18 -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 +2 -0
- package/lib/npm-run-series.js +80 -39
- 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.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 +2 -0
- package/lib/ps/connected-domain.js +202 -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.mjs +8 -0
- package/lib/ps/index.d.mts +26 -0
- package/lib/ps/index.d.ts +2 -0
- package/lib/ps/index.js +250 -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 +2 -0
- package/lib/ps/isWin.js +2 -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 +1 -0
- package/lib/ps/table-parser.js +268 -0
- package/lib/ps/table-parser.mjs +8 -0
- package/lib/submodule-install.cjs +118 -0
- package/lib/submodule-install.d.cts +2 -0
- package/lib/submodule-install.d.mts +141 -0
- package/lib/submodule-install.d.ts +141 -0
- package/lib/submodule-install.mjs +116 -0
- package/lib/utils.cjs +35 -0
- package/lib/utils.d.mts +20 -0
- package/lib/utils.d.ts +16 -0
- package/lib/utils.js +42 -28
- package/lib/utils.mjs +7 -0
- package/lib/yarn-reinstall.cjs +42 -0
- package/lib/yarn-reinstall.d.cts +1 -0
- package/lib/yarn-reinstall.d.mts +45 -0
- package/lib/yarn-reinstall.d.ts +45 -0
- package/lib/yarn-reinstall.mjs +50 -0
- package/package.json +80 -38
- package/readme.md +188 -40
- package/src/ps/index.js +285 -0
- package/test/package.json +19 -0
- package/index.js +0 -1
- package/lib/package-resolutions.json +0 -22
|
@@ -0,0 +1,359 @@
|
|
|
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/connected-domain.js
|
|
16
|
+
var require_connected_domain = __commonJS({
|
|
17
|
+
"src/ps/connected-domain.js"(exports2, module2) {
|
|
18
|
+
init_cjs_shims();
|
|
19
|
+
module2.exports = function(tdArray, indicator, hardlink) {
|
|
20
|
+
hardlink = hardlink || false;
|
|
21
|
+
if (!tdArray) {
|
|
22
|
+
throw new Error("tdArray must be provided");
|
|
23
|
+
}
|
|
24
|
+
if (!indicator) {
|
|
25
|
+
throw new Error("indicator must be provided");
|
|
26
|
+
}
|
|
27
|
+
tdArray = JSON.parse(JSON.stringify(tdArray));
|
|
28
|
+
var domains = {};
|
|
29
|
+
var domainUUID = 0;
|
|
30
|
+
var pointsHash = {};
|
|
31
|
+
tdArray.forEach(function(row, y) {
|
|
32
|
+
row.forEach(function(colItem, x) {
|
|
33
|
+
var identifier2 = indicator(colItem, x, y);
|
|
34
|
+
var neighbours = [];
|
|
35
|
+
if (tdArray[y - 1] && tdArray[y - 1][x] !== void 0) {
|
|
36
|
+
neighbours.push(pointsHash[x + "_" + (y - 1)]);
|
|
37
|
+
}
|
|
38
|
+
if (row[x - 1] !== void 0) {
|
|
39
|
+
neighbours.push(pointsHash[x - 1 + "_" + y]);
|
|
40
|
+
}
|
|
41
|
+
if (!hardlink) {
|
|
42
|
+
if (tdArray[y - 1] && tdArray[y - 1][x - 1] !== void 0) {
|
|
43
|
+
neighbours.push(pointsHash[x - 1 + "_" + (y - 1)]);
|
|
44
|
+
}
|
|
45
|
+
if (tdArray[y - 1] && tdArray[y - 1][x + 1] !== void 0) {
|
|
46
|
+
neighbours.push(pointsHash[x + 1 + "_" + (y - 1)]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (neighbours.length) {
|
|
50
|
+
var matched = false;
|
|
51
|
+
neighbours.forEach(function(neighbour) {
|
|
52
|
+
if (neighbour.identifier == identifier2) {
|
|
53
|
+
if (!matched) {
|
|
54
|
+
addPointToDomain(colItem, x, y, neighbour.domainId);
|
|
55
|
+
matched = true;
|
|
56
|
+
} else {
|
|
57
|
+
var colItemPoint = pointsHash[x + "_" + y];
|
|
58
|
+
if (neighbour.domainId != colItemPoint.domainId) {
|
|
59
|
+
mergeDomains(neighbour.domainId, colItemPoint.domainId);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (!matched) {
|
|
65
|
+
addNewDomain(colItem, x, y, identifier2);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
addNewDomain(colItem, x, y, identifier2);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var result = {
|
|
73
|
+
domains: [],
|
|
74
|
+
totalDomains: 0,
|
|
75
|
+
groupByIdentifier: {},
|
|
76
|
+
totalIdentifiers: 0
|
|
77
|
+
};
|
|
78
|
+
var domainId = null;
|
|
79
|
+
var identifier = null;
|
|
80
|
+
var domain = null;
|
|
81
|
+
for (domainId in domains) {
|
|
82
|
+
domain = domains[domainId];
|
|
83
|
+
domain.bounding = calculateBounding(domain.points);
|
|
84
|
+
identifier = domain.identifier;
|
|
85
|
+
result.domains.push(domain);
|
|
86
|
+
result.totalDomains++;
|
|
87
|
+
if (!(identifier in result.groupByIdentifier)) {
|
|
88
|
+
result.groupByIdentifier[identifier] = [];
|
|
89
|
+
result.totalIdentifiers++;
|
|
90
|
+
}
|
|
91
|
+
result.groupByIdentifier[identifier].push(domain);
|
|
92
|
+
}
|
|
93
|
+
function calculateBounding(points) {
|
|
94
|
+
var minX = null;
|
|
95
|
+
var minY = null;
|
|
96
|
+
var maxX = null;
|
|
97
|
+
var maxY = null;
|
|
98
|
+
points.forEach(function(point) {
|
|
99
|
+
if (minX === null || point.x < minX) {
|
|
100
|
+
minX = point.x;
|
|
101
|
+
}
|
|
102
|
+
if (minY === null || point.y < minY) {
|
|
103
|
+
minY = point.y;
|
|
104
|
+
}
|
|
105
|
+
if (maxX === null || point.x > maxX) {
|
|
106
|
+
maxX = point.x;
|
|
107
|
+
}
|
|
108
|
+
if (maxY === null || point.y > maxY) {
|
|
109
|
+
maxY = point.y;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
var w = maxX - minX;
|
|
113
|
+
var h = maxY - minY;
|
|
114
|
+
return {
|
|
115
|
+
x: minX,
|
|
116
|
+
y: minY,
|
|
117
|
+
w,
|
|
118
|
+
h
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function addNewDomain(point, x, y, identifier2) {
|
|
122
|
+
var newDomain = {
|
|
123
|
+
identifier: identifier2,
|
|
124
|
+
domainId: ++domainUUID,
|
|
125
|
+
bounding: {},
|
|
126
|
+
points: []
|
|
127
|
+
};
|
|
128
|
+
var newPoint = {
|
|
129
|
+
value: point,
|
|
130
|
+
x,
|
|
131
|
+
y,
|
|
132
|
+
identifier: identifier2,
|
|
133
|
+
domainId: newDomain.domainId
|
|
134
|
+
};
|
|
135
|
+
pointsHash[x + "_" + y] = {
|
|
136
|
+
value: point,
|
|
137
|
+
identifier: identifier2,
|
|
138
|
+
domainId: newDomain.domainId
|
|
139
|
+
};
|
|
140
|
+
newDomain.points.push(newPoint);
|
|
141
|
+
domains[newDomain.domainId] = newDomain;
|
|
142
|
+
}
|
|
143
|
+
function addPointToDomain(point, x, y, domainId2) {
|
|
144
|
+
var domain2 = domains[domainId2];
|
|
145
|
+
var newPoint = {
|
|
146
|
+
value: point,
|
|
147
|
+
x,
|
|
148
|
+
y,
|
|
149
|
+
identifier: domain2.identifier,
|
|
150
|
+
domainId: domainId2
|
|
151
|
+
};
|
|
152
|
+
pointsHash[x + "_" + y] = {
|
|
153
|
+
value: point,
|
|
154
|
+
identifier: domain2.identifier,
|
|
155
|
+
domainId: domainId2
|
|
156
|
+
};
|
|
157
|
+
domain2.points.push(newPoint);
|
|
158
|
+
}
|
|
159
|
+
function mergeDomains(domainAId, domainBId) {
|
|
160
|
+
var domainA = domains[domainAId];
|
|
161
|
+
var domainB = domains[domainBId];
|
|
162
|
+
if (domainA.identifier == domainB.identifier) {
|
|
163
|
+
domainB.domainId = domainA.domainId;
|
|
164
|
+
domainB.points.forEach(function(point) {
|
|
165
|
+
point.domainId = domainA.domainId;
|
|
166
|
+
pointsHash[point.x + "_" + point.y].domainId = domainA.domainId;
|
|
167
|
+
});
|
|
168
|
+
domainA.points = domainA.points.concat(domainB.points);
|
|
169
|
+
delete domains[domainBId];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// src/ps/table-parser.js
|
|
178
|
+
init_cjs_shims();
|
|
179
|
+
var ConnectedDomain = require_connected_domain();
|
|
180
|
+
var EMPTY_EX = /\s/;
|
|
181
|
+
module.exports.parse = function(output) {
|
|
182
|
+
var linesTmp = output.split(/(\r\n)|(\n\r)|\n|\r/);
|
|
183
|
+
var lines = [];
|
|
184
|
+
var titleInfo = {};
|
|
185
|
+
var twoDimArray = [];
|
|
186
|
+
linesTmp.forEach(function(line) {
|
|
187
|
+
if (line && line.trim()) {
|
|
188
|
+
lines.push(line);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
lines.forEach(function(line, index) {
|
|
192
|
+
if (index == 0) {
|
|
193
|
+
var fields = line.split(/\s+/);
|
|
194
|
+
var currentIndex = 0;
|
|
195
|
+
fields.forEach(function(field, idx) {
|
|
196
|
+
if (field) {
|
|
197
|
+
var info = titleInfo[field] = {};
|
|
198
|
+
var indexBegin = line.indexOf(field, currentIndex);
|
|
199
|
+
var indexEnd = currentIndex = indexBegin + field.length;
|
|
200
|
+
if (idx == 0) {
|
|
201
|
+
info.titleBegin = 0;
|
|
202
|
+
} else {
|
|
203
|
+
info.titleBegin = indexBegin;
|
|
204
|
+
}
|
|
205
|
+
if (idx == fields.length - 1) {
|
|
206
|
+
info.titleEnd = line.length - 1;
|
|
207
|
+
} else {
|
|
208
|
+
info.titleEnd = indexEnd;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
} else {
|
|
213
|
+
twoDimArray[index - 1] = line.split("");
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
var connectedDomains = ConnectedDomain(
|
|
217
|
+
twoDimArray,
|
|
218
|
+
function(value) {
|
|
219
|
+
if (EMPTY_EX.test(value)) {
|
|
220
|
+
return -1;
|
|
221
|
+
} else {
|
|
222
|
+
return 1;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
true
|
|
226
|
+
);
|
|
227
|
+
var valuesDomainsVerticalGroups = [];
|
|
228
|
+
connectedDomains.domains.sort(function(a, b) {
|
|
229
|
+
return a.bounding.x - b.bounding.x;
|
|
230
|
+
});
|
|
231
|
+
connectedDomains.domains.forEach(function(domain) {
|
|
232
|
+
if (domain.identifier === 1) {
|
|
233
|
+
var overlapped = false;
|
|
234
|
+
valuesDomainsVerticalGroups.forEach(function(group) {
|
|
235
|
+
var bounding = domain.bounding;
|
|
236
|
+
var left = bounding.x;
|
|
237
|
+
var right = bounding.x + bounding.w;
|
|
238
|
+
if (overlap(left, right, group.begin, group.end)) {
|
|
239
|
+
overlapped = true;
|
|
240
|
+
group.domains.push(domain);
|
|
241
|
+
group.begin = group.begin > left ? left : group.begin;
|
|
242
|
+
group.end = group.end < right ? right : group.end;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
if (!overlapped) {
|
|
246
|
+
valuesDomainsVerticalGroups.push({
|
|
247
|
+
begin: domain.bounding.x,
|
|
248
|
+
end: domain.bounding.x + domain.bounding.w,
|
|
249
|
+
domains: [domain]
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
valuesDomainsVerticalGroups.forEach(function(group) {
|
|
255
|
+
var title = null;
|
|
256
|
+
var info = null;
|
|
257
|
+
var overlapped = false;
|
|
258
|
+
var minimunLeftDistance = null;
|
|
259
|
+
var nearestLeftTitle = null;
|
|
260
|
+
var distance = null;
|
|
261
|
+
for (title in titleInfo) {
|
|
262
|
+
info = titleInfo[title];
|
|
263
|
+
if (group.begin > info.titleBegin) {
|
|
264
|
+
distance = group.begin - info.titleBegin;
|
|
265
|
+
if (!nearestLeftTitle || distance < minimunLeftDistance) {
|
|
266
|
+
nearestLeftTitle = title;
|
|
267
|
+
minimunLeftDistance = distance;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (overlap(group.begin, group.end, info.titleBegin, info.titleEnd)) {
|
|
271
|
+
overlapped = true;
|
|
272
|
+
info.titleBegin = info.titleBegin > group.begin ? group.begin : info.titleBegin;
|
|
273
|
+
info.titleEnd = info.titleEnd < group.end ? group.end : info.titleEnd;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (!overlapped && nearestLeftTitle) {
|
|
277
|
+
var nearestTitleField = titleInfo[nearestLeftTitle];
|
|
278
|
+
nearestTitleField.titleBegin = nearestTitleField.titleBegin > group.begin ? group.begin : nearestTitleField.titleBegin;
|
|
279
|
+
nearestTitleField.titleEnd = nearestTitleField.titleEnd < group.end ? group.end : nearestTitleField.titleEnd;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
var result = [];
|
|
283
|
+
lines.forEach(function(line, index) {
|
|
284
|
+
if (index > 0) {
|
|
285
|
+
var lineItem = {};
|
|
286
|
+
var title = null;
|
|
287
|
+
var info = null;
|
|
288
|
+
var value = null;
|
|
289
|
+
for (title in titleInfo) {
|
|
290
|
+
info = titleInfo[title];
|
|
291
|
+
value = line.substring(info.titleBegin, info.titleEnd + 1);
|
|
292
|
+
lineItem[title] = splitValue(value.trim());
|
|
293
|
+
}
|
|
294
|
+
result.push(lineItem);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
return result;
|
|
298
|
+
};
|
|
299
|
+
function overlap(begin1, end1, begin2, end2) {
|
|
300
|
+
return begin1 > begin2 && begin1 < end2 || // 2--1--2--1 or 2--1--1--2
|
|
301
|
+
end1 > begin2 && end1 < end2 || // 1--2--1--2 or 2--1--1--2
|
|
302
|
+
begin1 <= begin2 && end1 >= end2;
|
|
303
|
+
}
|
|
304
|
+
function splitValue(value) {
|
|
305
|
+
var match = value.match(/"/g);
|
|
306
|
+
if (!match || match.length == 1) {
|
|
307
|
+
return value.split(/\s+/);
|
|
308
|
+
} else {
|
|
309
|
+
var result = [];
|
|
310
|
+
var chunk = null;
|
|
311
|
+
var ifInWrappedChunk = false;
|
|
312
|
+
var ifInPureWrappedChunk = false;
|
|
313
|
+
var quotaCount = 0;
|
|
314
|
+
var maxQuotaCount = match.length % 2 == 0 ? match.length : match.length - 1;
|
|
315
|
+
var previousItem = null;
|
|
316
|
+
var values = value.split("");
|
|
317
|
+
values.forEach(function(item, index) {
|
|
318
|
+
if (item !== " ") {
|
|
319
|
+
if (item === '"') {
|
|
320
|
+
if (ifInWrappedChunk === false && quotaCount <= maxQuotaCount) {
|
|
321
|
+
ifInWrappedChunk = true;
|
|
322
|
+
quotaCount++;
|
|
323
|
+
if (previousItem === " " || previousItem === null) {
|
|
324
|
+
ifInPureWrappedChunk = true;
|
|
325
|
+
chunk = "";
|
|
326
|
+
} else {
|
|
327
|
+
chunk += item;
|
|
328
|
+
}
|
|
329
|
+
} else if (ifInWrappedChunk === true) {
|
|
330
|
+
ifInWrappedChunk = false;
|
|
331
|
+
quotaCount++;
|
|
332
|
+
if (ifInPureWrappedChunk === true) {
|
|
333
|
+
ifInPureWrappedChunk = false;
|
|
334
|
+
result.push(chunk);
|
|
335
|
+
chunk = null;
|
|
336
|
+
} else {
|
|
337
|
+
chunk += item;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
} else if (ifInWrappedChunk === false && (previousItem === " " || previousItem === null)) {
|
|
341
|
+
chunk = item;
|
|
342
|
+
} else {
|
|
343
|
+
chunk += item;
|
|
344
|
+
}
|
|
345
|
+
} else if (ifInWrappedChunk) {
|
|
346
|
+
chunk += item;
|
|
347
|
+
} else if (chunk !== null) {
|
|
348
|
+
result.push(chunk);
|
|
349
|
+
chunk = null;
|
|
350
|
+
}
|
|
351
|
+
previousItem = item;
|
|
352
|
+
if (index == values.length - 1 && chunk !== null) {
|
|
353
|
+
result.push(chunk);
|
|
354
|
+
chunk = null;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function parse(output: any): any[];
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* 1, define the edge ( begin and end ) of every title field
|
|
4
|
+
* 2, parse all the lines except the title line, get all the connected-domains
|
|
5
|
+
* 3, group all the connected-domains vertically overlapped.
|
|
6
|
+
* 4, a domain group belongs to a title field if they vertically overlapped
|
|
7
|
+
* 5, calculate all the edge info through the group domain and title field relations.
|
|
8
|
+
*/
|
|
9
|
+
var ConnectedDomain = require("./connected-domain");
|
|
10
|
+
var EMPTY_EX = /\s/;
|
|
11
|
+
/**
|
|
12
|
+
* The output sting of cmd to parse
|
|
13
|
+
* @param output
|
|
14
|
+
* @returns {Array}
|
|
15
|
+
*/
|
|
16
|
+
module.exports.parse = function (output) {
|
|
17
|
+
// Split into lines
|
|
18
|
+
// Basically, the EOL should be:
|
|
19
|
+
// - windows: \r\n
|
|
20
|
+
// - *nix: \n
|
|
21
|
+
// But i'm trying to get every possibilities covered.
|
|
22
|
+
var linesTmp = output.split(/(\r\n)|(\n\r)|\n|\r/);
|
|
23
|
+
// valid lines
|
|
24
|
+
var lines = [];
|
|
25
|
+
// title field info, mapped with filed name.
|
|
26
|
+
var titleInfo = {};
|
|
27
|
+
// the two dimensional array of the lines
|
|
28
|
+
var twoDimArray = [];
|
|
29
|
+
// get rid of all the empty lines.
|
|
30
|
+
linesTmp.forEach(function (line) {
|
|
31
|
+
if (line && line.trim()) {
|
|
32
|
+
lines.push(line);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
// build title fields edge info
|
|
36
|
+
// build two dimensional array for Connected-Domain to parse.
|
|
37
|
+
lines.forEach(function (line, index) {
|
|
38
|
+
// Treat the first line as the title fields line
|
|
39
|
+
if (index == 0) {
|
|
40
|
+
var fields = line.split(/\s+/);
|
|
41
|
+
var currentIndex = 0;
|
|
42
|
+
// record the beginning and ending for each field
|
|
43
|
+
fields.forEach(function (field, idx) {
|
|
44
|
+
if (field) {
|
|
45
|
+
var info = (titleInfo[field] = {});
|
|
46
|
+
var indexBegin = line.indexOf(field, currentIndex);
|
|
47
|
+
var indexEnd = (currentIndex = indexBegin + field.length);
|
|
48
|
+
if (idx == 0) {
|
|
49
|
+
info.titleBegin = 0;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
info.titleBegin = indexBegin;
|
|
53
|
+
}
|
|
54
|
+
if (idx == fields.length - 1) {
|
|
55
|
+
info.titleEnd = line.length - 1;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
info.titleEnd = indexEnd;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
twoDimArray[index - 1] = line.split("");
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// In the connected-domain aspect of view, all the blanks are connected, and all the non-blanks are connected.
|
|
68
|
+
var connectedDomains = ConnectedDomain(twoDimArray, function (value) {
|
|
69
|
+
if (EMPTY_EX.test(value)) {
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
}, true);
|
|
76
|
+
// all the connected domains grouped if they are vertically overlapped.
|
|
77
|
+
var valuesDomainsVerticalGroups = [];
|
|
78
|
+
// sore the domain list make 'x' in ascending order, it will prevent the situation that:
|
|
79
|
+
// 1, two domains are not overlapped, so two groups are created for them at first
|
|
80
|
+
// 2, another domain is found overlapped with both of the domains at the first step.
|
|
81
|
+
// 3, In this situation the three groups have to be merged, which is complicated to implement.
|
|
82
|
+
//
|
|
83
|
+
// If the list is sorted in this order, this situation can't happen, because:
|
|
84
|
+
// - 1, If two non-overlapped domains A, B ( the "x" value of A less than B ) are found first.
|
|
85
|
+
// - 2, Since the list is in 'x' ascending order, the 'x' values of the following domains must larger or equal to the "x" of B, which means they will never overlapped with domain A.
|
|
86
|
+
// - 3, So this situation can't happen.
|
|
87
|
+
connectedDomains.domains.sort(function (a, b) {
|
|
88
|
+
return a.bounding.x - b.bounding.x;
|
|
89
|
+
});
|
|
90
|
+
// Group domains vertically overlapped.
|
|
91
|
+
connectedDomains.domains.forEach(function (domain) {
|
|
92
|
+
// only handle un-empty domain
|
|
93
|
+
if (domain.identifier === 1) {
|
|
94
|
+
var overlapped = false;
|
|
95
|
+
// If overlapped
|
|
96
|
+
valuesDomainsVerticalGroups.forEach(function (group) {
|
|
97
|
+
var bounding = domain.bounding;
|
|
98
|
+
var left = bounding.x;
|
|
99
|
+
var right = bounding.x + bounding.w;
|
|
100
|
+
if (overlap(left, right, group.begin, group.end)) {
|
|
101
|
+
overlapped = true;
|
|
102
|
+
group.domains.push(domain);
|
|
103
|
+
group.begin = group.begin > left ? left : group.begin;
|
|
104
|
+
group.end = group.end < right ? right : group.end;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
// If not overlapped with any group, then create a new group
|
|
108
|
+
if (!overlapped) {
|
|
109
|
+
valuesDomainsVerticalGroups.push({
|
|
110
|
+
begin: domain.bounding.x,
|
|
111
|
+
end: domain.bounding.x + domain.bounding.w,
|
|
112
|
+
domains: [domain]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
// connect all the groups to the title fields
|
|
118
|
+
valuesDomainsVerticalGroups.forEach(function (group) {
|
|
119
|
+
var title = null;
|
|
120
|
+
var info = null;
|
|
121
|
+
var overlapped = false;
|
|
122
|
+
var minimunLeftDistance = null;
|
|
123
|
+
var nearestLeftTitle = null;
|
|
124
|
+
var distance = null;
|
|
125
|
+
for (title in titleInfo) {
|
|
126
|
+
info = titleInfo[title];
|
|
127
|
+
/**
|
|
128
|
+
* The calculation below is to find the nearest left title field to the group, in case no overlapped title field found.
|
|
129
|
+
*/
|
|
130
|
+
if (group.begin > info.titleBegin) {
|
|
131
|
+
distance = group.begin - info.titleBegin;
|
|
132
|
+
if (!nearestLeftTitle || distance < minimunLeftDistance) {
|
|
133
|
+
nearestLeftTitle = title;
|
|
134
|
+
minimunLeftDistance = distance;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (overlap(group.begin, group.end, info.titleBegin, info.titleEnd)) {
|
|
138
|
+
overlapped = true;
|
|
139
|
+
info.titleBegin = info.titleBegin > group.begin ? group.begin : info.titleBegin;
|
|
140
|
+
info.titleEnd = info.titleEnd < group.end ? group.end : info.titleEnd;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Groups not match any title field belongs to the nearest left title field
|
|
144
|
+
if (!overlapped && nearestLeftTitle) {
|
|
145
|
+
var nearestTitleField = titleInfo[nearestLeftTitle];
|
|
146
|
+
nearestTitleField.titleBegin =
|
|
147
|
+
nearestTitleField.titleBegin > group.begin ? group.begin : nearestTitleField.titleBegin;
|
|
148
|
+
nearestTitleField.titleEnd = nearestTitleField.titleEnd < group.end ? group.end : nearestTitleField.titleEnd;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
// The final result
|
|
152
|
+
var result = [];
|
|
153
|
+
// Since we have got all the title bounding edges, we can split all the lines into values now
|
|
154
|
+
lines.forEach(function (line, index) {
|
|
155
|
+
// skip the first line
|
|
156
|
+
if (index > 0) {
|
|
157
|
+
var lineItem = {};
|
|
158
|
+
var title = null;
|
|
159
|
+
var info = null;
|
|
160
|
+
var value = null;
|
|
161
|
+
for (title in titleInfo) {
|
|
162
|
+
info = titleInfo[title];
|
|
163
|
+
value = line.substring(info.titleBegin, info.titleEnd + 1);
|
|
164
|
+
lineItem[title] = splitValue(value.trim());
|
|
165
|
+
}
|
|
166
|
+
result.push(lineItem);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
return result;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Test if two bounding overlapped vertically
|
|
173
|
+
* @param begin1
|
|
174
|
+
* @param end1
|
|
175
|
+
* @param begin2
|
|
176
|
+
* @param end2
|
|
177
|
+
* @returns {boolean}
|
|
178
|
+
*/
|
|
179
|
+
function overlap(begin1, end1, begin2, end2) {
|
|
180
|
+
return ((begin1 > begin2 && begin1 < end2) || // 2--1--2--1 or 2--1--1--2
|
|
181
|
+
(end1 > begin2 && end1 < end2) || // 1--2--1--2 or 2--1--1--2
|
|
182
|
+
(begin1 <= begin2 && end1 >= end2)); // 21--12 or 1--2--2--1
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* transform a string value into array. It's not just split(), but also to consider some chunk that wrapped with `"`, like below:
|
|
186
|
+
* "C:\Program Files\Google\Chrome\Application\chrome.exe" --type=renderer --lang=zh-CN, `C:\Program Files\Google\Chrome\Application\chrome.exe` should be treated as a whole,
|
|
187
|
+
* also, be careful don't be mislead by format like `--name="neekey"`, even more complicated: `--name="Neekey Ni"`
|
|
188
|
+
* so, `"C:\Program Files\Internet Explorer\iexplore.exe" --name="Jack Neekey"` should split into:
|
|
189
|
+
* - C:\Program Files\Internet Explorer\iexplore.exe // without `"`
|
|
190
|
+
* - --name="Jack Neekey" // with `"`
|
|
191
|
+
*/
|
|
192
|
+
function splitValue(value) {
|
|
193
|
+
var match = value.match(/"/g);
|
|
194
|
+
// If only one " found, then just ignore it
|
|
195
|
+
if (!match || match.length == 1) {
|
|
196
|
+
return value.split(/\s+/);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
var result = [];
|
|
200
|
+
var chunk = null;
|
|
201
|
+
var ifInWrappedChunk = false;
|
|
202
|
+
var ifInPureWrappedChunk = false;
|
|
203
|
+
var quotaCount = 0;
|
|
204
|
+
// If the match length is a even, than nothing special, if a odd, ignore the last one.
|
|
205
|
+
var maxQuotaCount = match.length % 2 == 0 ? match.length : match.length - 1;
|
|
206
|
+
var previousItem = null;
|
|
207
|
+
var values = value.split("");
|
|
208
|
+
values.forEach(function (item, index) {
|
|
209
|
+
if (item !== " ") {
|
|
210
|
+
if (item === '"') {
|
|
211
|
+
// quota chunk begin
|
|
212
|
+
if (ifInWrappedChunk === false && quotaCount <= maxQuotaCount) {
|
|
213
|
+
ifInWrappedChunk = true;
|
|
214
|
+
quotaCount++;
|
|
215
|
+
// pure quota chunk begin
|
|
216
|
+
if (previousItem === " " || previousItem === null) {
|
|
217
|
+
ifInPureWrappedChunk = true;
|
|
218
|
+
chunk = "";
|
|
219
|
+
}
|
|
220
|
+
// normal continue
|
|
221
|
+
else {
|
|
222
|
+
chunk += item;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// quota chunk end
|
|
226
|
+
else if (ifInWrappedChunk === true) {
|
|
227
|
+
ifInWrappedChunk = false;
|
|
228
|
+
quotaCount++;
|
|
229
|
+
// pure quota chunk end
|
|
230
|
+
if (ifInPureWrappedChunk === true) {
|
|
231
|
+
ifInPureWrappedChunk = false;
|
|
232
|
+
result.push(chunk);
|
|
233
|
+
chunk = null;
|
|
234
|
+
}
|
|
235
|
+
// normal continue
|
|
236
|
+
else {
|
|
237
|
+
chunk += item;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// normal begin
|
|
242
|
+
else if (ifInWrappedChunk === false && (previousItem === " " || previousItem === null)) {
|
|
243
|
+
chunk = item;
|
|
244
|
+
}
|
|
245
|
+
// normal or quota chunk continue.
|
|
246
|
+
else {
|
|
247
|
+
chunk += item;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// quota chunk continue, in quota chunk, blank is valid.
|
|
251
|
+
else if (ifInWrappedChunk) {
|
|
252
|
+
chunk += item;
|
|
253
|
+
}
|
|
254
|
+
// if not in quota chunk, them a blank means an end. But make sure chunk is exist, cause that could be blanks at the beginning.
|
|
255
|
+
else if (chunk !== null) {
|
|
256
|
+
result.push(chunk);
|
|
257
|
+
chunk = null;
|
|
258
|
+
}
|
|
259
|
+
previousItem = item;
|
|
260
|
+
// If this is the last one, but chunk is not end
|
|
261
|
+
if (index == values.length - 1 && chunk !== null) {
|
|
262
|
+
result.push(chunk);
|
|
263
|
+
chunk = null;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
require_table_parser
|
|
4
|
+
} from "../chunk-3LOB2P54.mjs";
|
|
5
|
+
import "../chunk-4LEXWIIF.mjs";
|
|
6
|
+
import "../chunk-VXZQNLPU.mjs";
|
|
7
|
+
import "../chunk-FB6YIQYR.mjs";
|
|
8
|
+
export default require_table_parser();
|