(text: string)
| 82 | * Returns `text` itself when it has no such run. |
| 83 | */ |
| 84 | export function withoutLongRuns(text: string): string { |
| 85 | let parts: string[] | null = null; |
| 86 | let copied = 0; |
| 87 | let start = -1; |
| 88 | for (let i = 0; i <= text.length; i++) { |
| 89 | const code = i < text.length ? text.charCodeAt(i) : 0; |
| 90 | if (code < 128 && IN_NAME_RUN[code] === 1) { |
| 91 | if (start < 0) start = i; |
| 92 | continue; |
| 93 | } |
| 94 | if (start >= 0) { |
| 95 | if (i - start > LONGEST_NAME_RUN) { |
| 96 | (parts ??= []).push(text.slice(copied, start), RUN_FILL.repeat(i - start)); |
| 97 | copied = i; |
| 98 | } |
| 99 | start = -1; |
| 100 | } |
| 101 | } |
| 102 | if (!parts) return text; |
| 103 | parts.push(text.slice(copied)); |
| 104 | return parts.join(''); |
| 105 | } |
| 106 | |
| 107 | /** A source file's stats, and its bytes when they are within the limit (null = oversize). */ |
| 108 | export interface BoundedSource { |
no test coverage detected