20 lines
669 B
JavaScript
20 lines
669 B
JavaScript
|
export function parseExternalContext(externalContext) {
|
||
|
// If there's no external context, return nothing.
|
||
|
if (!externalContext)
|
||
|
return {}
|
||
|
|
||
|
// Remove start and end tag ↓ Only care about the first "externalConext"
|
||
|
externalContext = externalContext[0].replace(/%%-\n|-%%\n/g, "")
|
||
|
|
||
|
let parsedContext = {}
|
||
|
externalContext.split("\n").forEach(line => {
|
||
|
// If the line is falsey; leave.
|
||
|
if (!line) return
|
||
|
|
||
|
// Assign properties to parsedContext and give them their corresponding values.
|
||
|
line = line.split(/:/)
|
||
|
parsedContext[line[0]] = line[1].replace(/^\s/, "")
|
||
|
})
|
||
|
|
||
|
return parsedContext
|
||
|
}
|