MCPcopy Index your code
hub / github.com/github/docs / getExceptionRedirects

Function getExceptionRedirects

lib/redirects/exception-redirects.js:4–26  ·  view source on GitHub ↗
(exceptionsTxtFile)

Source from the content-addressed store, hash-verified

2
3// This function expects a .txt file in a specific format.
4export 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}

Callers 3

precompileRedirectsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected