I have the following block of code:
data.split('\n').map(l => {
if (/^videoW/.exec(l)) {
vidConf.videoW = l.split('=')[1]
}
if (/^videoH/.exec(l)) {
vidConf.videoH = l.split('=')[1]
}
if (/^videoT/.exec(l)) {
vidConf.videoT = l.split('=')[1]
}
if (/^videoL/.exec(l)) {
vidConf.videoL = l.split('=')[1]
}
if (/^time=/.exec(l)) {
vidConf.timeImg = l.split('=')[1]
}
if (/^auto=/.exec(l)) {
vidConf.videoA = l.split('=')[1]
}
if (/^typeP=/.exec(l)) {
vidConf.typeP = l.split('=')[1]
}
})
To the data array I cut it by the line breaks ( \n
), because I extract it from an external file and perform a map
on it to check the existence of some variables in the using regular expressions and in this way pass the data to the variable vidConf .
How could I refactor this code avoiding so many sentences if
, and achieving the same result?