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
|
||||
value = true
|
||||
}
|
||||
webPreferences[name] = value
|
||||
webPreferences[key] = value
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +1,19 @@
|
|||
// parses a feature string that has the format used in window.open()
|
||||
// - `str` input string
|
||||
// - `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 ','
|
||||
let i, len
|
||||
let strTokens = params.str.split(/,\s*/)
|
||||
for (i = 0, len = strTokens.length; i < len; i++) {
|
||||
features.split(/,\s*/).forEach((feature) => {
|
||||
// expected form is either a key by itself (true boolean flag)
|
||||
// or a key/value, in the form of 'key=value'
|
||||
// split the tokens by '='
|
||||
let kv = strTokens[i]
|
||||
let kvTokens = kv.split(/\s*=/)
|
||||
let key = kvTokens[0]
|
||||
let value = kvTokens[1]
|
||||
if (!key) continue
|
||||
let [key, value] = feature.split(/\s*=/)
|
||||
if (!key) return
|
||||
|
||||
// interpret the value as a boolean, if possible
|
||||
value = (value === 'yes' || value === '1') ? true : (value === 'no' || value === '0') ? false : value
|
||||
|
||||
// emit the parsed pair
|
||||
emit(key, value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue