( fileContent: string, header: string, )
| 107 | * possibly-empty new content + an action flag. |
| 108 | */ |
| 109 | export function removeTomlTable( |
| 110 | fileContent: string, |
| 111 | header: string, |
| 112 | ): { content: string; action: 'removed' | 'not-found' } { |
| 113 | const headerLine = `[${header}]`; |
| 114 | const headerIdx = findHeaderIndex(fileContent, headerLine); |
| 115 | if (headerIdx === -1) return { content: fileContent, action: 'not-found' }; |
| 116 | |
| 117 | const blockEnd = findNextTableHeader(fileContent, headerIdx + headerLine.length); |
| 118 | const before = fileContent.substring(0, headerIdx).replace(/\n+$/, ''); |
| 119 | const after = fileContent.substring(blockEnd).replace(/^\n+/, ''); |
| 120 | const joined = before + (before && after ? '\n\n' : '') + after; |
| 121 | return { content: joined, action: 'removed' }; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Locate the byte index of a header line (`[foo.bar]`) when it |
no test coverage detected