* Removes spans from a string, returning the string with those character * ranges removed.
(command: string, spans: Array<[number, number]>)
| 178 | * ranges removed. |
| 179 | */ |
| 180 | function removeSpans(command: string, spans: Array<[number, number]>): string { |
| 181 | if (spans.length === 0) return command |
| 182 | |
| 183 | // Drop inner spans that are fully contained in an outer one, then sort by |
| 184 | // start index descending so we can splice without offset shifts. |
| 185 | const sorted = dropContainedSpans(spans).sort((a, b) => b[0] - a[0]) |
| 186 | let result = command |
| 187 | for (const [start, end] of sorted) { |
| 188 | result = result.slice(0, start) + result.slice(end) |
| 189 | } |
| 190 | return result |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Replaces spans with just the quote delimiters (preserving ' and " characters). |
no test coverage detected