( text: string, )
| 29 | } |
| 30 | |
| 31 | export function findTokenBudgetPositions( |
| 32 | text: string, |
| 33 | ): Array<{ start: number; end: number }> { |
| 34 | const positions: Array<{ start: number; end: number }> = [] |
| 35 | const startMatch = text.match(SHORTHAND_START_RE) |
| 36 | if (startMatch) { |
| 37 | const offset = |
| 38 | startMatch.index! + |
| 39 | startMatch[0].length - |
| 40 | startMatch[0].trimStart().length |
| 41 | positions.push({ |
| 42 | start: offset, |
| 43 | end: startMatch.index! + startMatch[0].length, |
| 44 | }) |
| 45 | } |
| 46 | const endMatch = text.match(SHORTHAND_END_RE) |
| 47 | if (endMatch) { |
| 48 | // Avoid double-counting when input is just "+500k" |
| 49 | const endStart = endMatch.index! + 1 // +1: regex includes leading \s |
| 50 | const alreadyCovered = positions.some( |
| 51 | p => endStart >= p.start && endStart < p.end, |
| 52 | ) |
| 53 | if (!alreadyCovered) { |
| 54 | positions.push({ |
| 55 | start: endStart, |
| 56 | end: endMatch.index! + endMatch[0].length, |
| 57 | }) |
| 58 | } |
| 59 | } |
| 60 | for (const match of text.matchAll(VERBOSE_RE_G)) { |
| 61 | positions.push({ start: match.index, end: match.index + match[0].length }) |
| 62 | } |
| 63 | return positions |
| 64 | } |
| 65 | |
| 66 | export function getBudgetContinuationMessage( |
| 67 | pct: number, |
no test coverage detected