(exceptionsTxtFile)
| 2 | |
| 3 | // This function expects a .txt file in a specific format. |
| 4 | export default function getExceptionRedirects(exceptionsTxtFile) { |
| 5 | const exceptions = {} |
| 6 | const exceptionRedirectsLines = fs |
| 7 | .readFileSync(exceptionsTxtFile, 'utf-8') |
| 8 | .split('\n') |
| 9 | .filter(Boolean) |
| 10 | .map((line) => line.trim()) |
| 11 | .filter((line) => !line.startsWith('#')) |
| 12 | |
| 13 | let parent = null |
| 14 | for (const line of exceptionRedirectsLines) { |
| 15 | if (line.startsWith('-')) { |
| 16 | if (!parent) { |
| 17 | throw new Error("first line can't start with a `-`") |
| 18 | } |
| 19 | exceptions[line.slice(1).trim()] = parent |
| 20 | } else { |
| 21 | parent = line |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | return exceptions |
| 26 | } |
no outgoing calls
no test coverage detected