MCPcopy Index your code
hub / github.com/darkreader/darkreader / splitCode

Function splitCode

tests/browser/coverage.js:13–42  ·  view source on GitHub ↗

* @param {string} code * @param {{start: number; end: number}[]} ranges * @returns {CodePart[]}

(code, ranges)

Source from the content-addressed store, hash-verified

11 * @returns {CodePart[]}
12 */
13function splitCode(code, ranges) {
14 /** @type {CodePart[]} */
15 const parts = [];
16
17 if (ranges.length === 0) {
18 parts.push({text: code, covered: false});
19 return;
20 }
21
22 if (ranges[0].start > 0) {
23 parts.push({text: code.substring(0, ranges[0].start), covered: false});
24 }
25
26 const lastRange = ranges[ranges.length - 1];
27
28 for (let i = 0; i < ranges.length; i++) {
29 const range = ranges[i];
30 parts.push({text: code.substring(range.start, range.end), covered: true});
31 if (range !== lastRange) {
32 const nextRange = ranges[i + 1];
33 parts.push({text: code.substring(range.end, nextRange.start), covered: false});
34 }
35 }
36
37 if (lastRange.end < code.length) {
38 parts.push({text: code.substring(lastRange.end), covered: false});
39 }
40
41 return parts;
42}
43
44function red(/** @type {string} */text) {
45 return `\x1b[31m${text}\x1b[0m`;

Callers 2

logCoverageFunction · 0.85
getCoverageInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…