(text: string)
| 130 | * Returns `text` itself when it has no such run. |
| 131 | */ |
| 132 | export function withoutLongRuns(text: string): string { |
| 133 | let parts: string[] | null = null; |
| 134 | let copied = 0; |
| 135 | let start = -1; |
| 136 | for (let i = 0; i <= text.length; i++) { |
| 137 | const code = i < text.length ? text.charCodeAt(i) : 0; |
| 138 | if (code < 128 && IN_NAME_RUN[code] === 1) { |
| 139 | if (start < 0) start = i; |
| 140 | continue; |
| 141 | } |
| 142 | if (start >= 0) { |
| 143 | if (i - start > LONGEST_NAME_RUN) { |
| 144 | (parts ??= []).push(text.slice(copied, start), RUN_FILL.repeat(i - start)); |
| 145 | copied = i; |
| 146 | } |
| 147 | start = -1; |
| 148 | } |
| 149 | } |
| 150 | if (!parts) return text; |
| 151 | parts.push(text.slice(copied)); |
| 152 | return parts.join(''); |
| 153 | } |
| 154 | |
| 155 | /** A source file's stats, and its bytes when they are within the limit (null = oversize). */ |
| 156 | export interface BoundedSource { |
no test coverage detected