Skip to content

Instantly share code, notes, and snippets.

@jeovazero
Created November 7, 2019 13:48
Show Gist options
  • Save jeovazero/6f57b7210108269df68e82332d5e03ab to your computer and use it in GitHub Desktop.
Save jeovazero/6f57b7210108269df68e82332d5e03ab to your computer and use it in GitHub Desktop.
const expr = /export \{?((.|\s)+?)\}? from \'(.+)\'/gmi
process.stdin.setEncoding('utf8');
let input = ''
process.stdin.on('data', (chunk) => {
input += chunk
});
const getKeys = (text) => {
return text.replace(/\s/gm, '').split(',')
}
const parse = (text) => {
let ans;
const mapping = {}
while(true) {
ans = expr.exec(text)
if (ans !== null)
getKeys(ans[1]).forEach(cur => {
mapping[cur] = ans[3]
})
else break;
}
return mapping
}
process.stdin.on('end', () => {
console.log(parse(input))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment