* @param {string} code * @param {{start: number; end: number}[]} ranges * @returns {CodePart[]}
(code, ranges)
| 11 | * @returns {CodePart[]} |
| 12 | */ |
| 13 | function 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 | |
| 44 | function red(/** @type {string} */text) { |
| 45 | return `\x1b[31m${text}\x1b[0m`; |
no outgoing calls
no test coverage detected
searching dependent graphs…