2021-08-06 14:46:16 +02:00
|
|
|
export function parseExternalContext(externalContext) {
|
2021-08-08 19:00:30 +02:00
|
|
|
// 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, "")
|
2021-08-07 10:46:48 +02:00
|
|
|
|
2021-08-06 14:46:16 +02:00
|
|
|
let parsedContext = {}
|
|
|
|
externalContext.split("\n").forEach(line => {
|
|
|
|
// If the line is falsey; leave.
|
|
|
|
if (!line) return
|
|
|
|
|
2021-08-07 10:46:48 +02:00
|
|
|
// Assign properties to parsedContext and give them their corresponding values.
|
2021-08-06 14:46:16 +02:00
|
|
|
line = line.split(/:/)
|
|
|
|
parsedContext[line[0]] = line[1].replace(/^\s/, "")
|
|
|
|
})
|
|
|
|
|
|
|
|
return parsedContext
|
|
|
|
}
|