16 lines
497 B
JavaScript
16 lines
497 B
JavaScript
|
export function parseExternalContext(externalContext) {
|
||
|
// Remove start and end tag
|
||
|
externalContext = externalContext.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 values.
|
||
|
line = line.split(/:/)
|
||
|
parsedContext[line[0]] = line[1].replace(/^\s/, "")
|
||
|
})
|
||
|
|
||
|
return parsedContext
|
||
|
}
|