Use forEach and destructuring for parsing features
This commit is contained in:
parent
2556ed8744
commit
3aad6a0c99
2 changed files with 7 additions and 12 deletions
|
@ -193,7 +193,7 @@ const attachGuest = function (embedder, elementInstanceId, guestInstanceId, para
|
||||||
// no value was specified, default it to true
|
// no value was specified, default it to true
|
||||||
value = true
|
value = true
|
||||||
}
|
}
|
||||||
webPreferences[name] = value
|
webPreferences[key] = value
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,19 @@
|
||||||
// parses a feature string that has the format used in window.open()
|
// parses a feature string that has the format used in window.open()
|
||||||
// - `str` input string
|
// - `str` input string
|
||||||
// - `emit` function(key, value) - called for each parsed KV
|
// - `emit` function(key, value) - called for each parsed KV
|
||||||
module.exports = function parseFeaturesString (str, emit) {
|
module.exports = function parseFeaturesString (features, emit) {
|
||||||
// split the string by ','
|
// split the string by ','
|
||||||
let i, len
|
features.split(/,\s*/).forEach((feature) => {
|
||||||
let strTokens = params.str.split(/,\s*/)
|
|
||||||
for (i = 0, len = strTokens.length; i < len; i++) {
|
|
||||||
// expected form is either a key by itself (true boolean flag)
|
// expected form is either a key by itself (true boolean flag)
|
||||||
// or a key/value, in the form of 'key=value'
|
// or a key/value, in the form of 'key=value'
|
||||||
// split the tokens by '='
|
// split the tokens by '='
|
||||||
let kv = strTokens[i]
|
let [key, value] = feature.split(/\s*=/)
|
||||||
let kvTokens = kv.split(/\s*=/)
|
if (!key) return
|
||||||
let key = kvTokens[0]
|
|
||||||
let value = kvTokens[1]
|
|
||||||
if (!key) continue
|
|
||||||
|
|
||||||
// interpret the value as a boolean, if possible
|
// interpret the value as a boolean, if possible
|
||||||
value = (value === 'yes' || value === '1') ? true : (value === 'no' || value === '0') ? false : value
|
value = (value === 'yes' || value === '1') ? true : (value === 'no' || value === '0') ? false : value
|
||||||
|
|
||||||
// emit the parsed pair
|
// emit the parsed pair
|
||||||
emit(key, value)
|
emit(key, value)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue