monocart-coverage-reports 2.3.3 → 2.3.4

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.
@@ -248,6 +248,41 @@ const Util = {
248
248
  return false;
249
249
  },
250
250
 
251
+ findInRanges: (startPos, endPos, rangeList, startKey = 'start', endKey = 'end') => {
252
+ if (!Util.isList(rangeList)) {
253
+ return;
254
+ }
255
+
256
+ const quickFindRange = (position, ranges) => {
257
+ let start = 0;
258
+ let end = ranges.length - 1;
259
+ while (end - start > 1) {
260
+ const i = Math.floor((start + end) * 0.5);
261
+ const item = ranges[i];
262
+ if (position < item[startKey]) {
263
+ end = i;
264
+ continue;
265
+ }
266
+ if (position > item[endKey]) {
267
+ start = i;
268
+ continue;
269
+ }
270
+ return ranges[i];
271
+ }
272
+ // last two items, less is start
273
+ const endItem = ranges[end];
274
+ if (position < endItem[startKey]) {
275
+ return ranges[start];
276
+ }
277
+ return ranges[end];
278
+ };
279
+
280
+ const range = quickFindRange(startPos, rangeList);
281
+ if (startPos >= range[startKey] && endPos <= range[endKey]) {
282
+ return range;
283
+ }
284
+ },
285
+
251
286
  getRangeLines: (sLoc, eLoc) => {
252
287
 
253
288
  const lines = [];
@@ -273,7 +308,7 @@ const Util = {
273
308
  lines.push({
274
309
  line: sLoc.line,
275
310
  entire,
276
- range: {
311
+ pieces: {
277
312
  start: sLoc.column,
278
313
  end: sLoc.length
279
314
  }
@@ -289,7 +324,7 @@ const Util = {
289
324
  lines.push({
290
325
  line: sLoc.line,
291
326
  entire,
292
- range: {
327
+ pieces: {
293
328
  start: sLoc.column,
294
329
  end: eLoc.column
295
330
  }
@@ -307,7 +342,7 @@ const Util = {
307
342
  lines.push({
308
343
  line: eLoc.line,
309
344
  entire,
310
- range: {
345
+ pieces: {
311
346
  start: eLoc.indent,
312
347
  end: eLoc.column
313
348
  }
@@ -332,7 +367,7 @@ const Util = {
332
367
  lines.push({
333
368
  line: i,
334
369
  entire: true
335
- // no range for entire line
370
+ // no pieces for entire line
336
371
  });
337
372
  }
338
373
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -1,39 +0,0 @@
1
- const Util = require('../utils/util.js');
2
-
3
- const quickFindRange = (position, ranges, startKey, endKey) => {
4
- let start = 0;
5
- let end = ranges.length - 1;
6
- while (end - start > 1) {
7
- const i = Math.floor((start + end) * 0.5);
8
- const item = ranges[i];
9
- if (position < item[startKey]) {
10
- end = i;
11
- continue;
12
- }
13
- if (position > item[endKey]) {
14
- start = i;
15
- continue;
16
- }
17
- return ranges[i];
18
- }
19
- // last two items, less is start
20
- const endItem = ranges[end];
21
- if (position < endItem[startKey]) {
22
- return ranges[start];
23
- }
24
- return ranges[end];
25
- };
26
-
27
-
28
- const findInRanges = (start, end, ranges, startKey = 'startOffset', endKey = 'endOffset') => {
29
- if (!Util.isList(ranges)) {
30
- return;
31
- }
32
- const range = quickFindRange(start, ranges, startKey, endKey);
33
- if (start >= range[startKey] && end <= range[endKey]) {
34
- return range;
35
- }
36
- };
37
-
38
-
39
- module.exports = findInRanges;