asarfuckery/electronasar/canary/common/parse-features-string.js

22 lines
739 B
JavaScript
Raw Normal View History

2019-02-06 20:27:58 +00:00
'use strict'
// parses a feature string that has the format used in window.open()
// - `features` input string
// - `emit` function(key, value) - called for each parsed KV
module.exports = function parseFeaturesString (features, emit) {
2019-04-05 18:06:38 +00:00
features = `${features}`.trim()
2019-02-06 20:27:58 +00:00
// split the string by ','
2019-04-05 18:06:38 +00:00
features.split(/\s*,\s*/).forEach((feature) => {
2019-02-06 20:27:58 +00:00
// expected form is either a key by itself or a key/value pair in the form of
// 'key=value'
2019-04-05 18:06:38 +00:00
let [key, value] = feature.split(/\s*=\s*/)
2019-02-06 20:27:58 +00:00
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)
})
}