2018-09-22 12:28:50 +00:00
|
|
|
'use strict'
|
|
|
|
|
2016-10-25 01:21:42 +00:00
|
|
|
// parses a feature string that has the format used in window.open()
|
2016-10-25 01:36:43 +00:00
|
|
|
// - `features` input string
|
2016-10-25 01:21:42 +00:00
|
|
|
// - `emit` function(key, value) - called for each parsed KV
|
2016-10-25 01:31:50 +00:00
|
|
|
module.exports = function parseFeaturesString (features, emit) {
|
2016-12-02 01:35:26 +00:00
|
|
|
features = `${features}`
|
2016-10-25 01:21:42 +00:00
|
|
|
// split the string by ','
|
2016-10-25 01:31:50 +00:00
|
|
|
features.split(/,\s*/).forEach((feature) => {
|
2016-10-25 01:36:43 +00:00
|
|
|
// expected form is either a key by itself or a key/value pair in the form of
|
|
|
|
// 'key=value'
|
2016-10-25 01:31:50 +00:00
|
|
|
let [key, value] = feature.split(/\s*=/)
|
|
|
|
if (!key) return
|
2016-10-25 01:21:42 +00:00
|
|
|
|
2016-10-25 01:31:50 +00:00
|
|
|
// interpret the value as a boolean, if possible
|
2016-10-25 01:21:42 +00:00
|
|
|
value = (value === 'yes' || value === '1') ? true : (value === 'no' || value === '0') ? false : value
|
|
|
|
|
|
|
|
// emit the parsed pair
|
|
|
|
emit(key, value)
|
2016-10-25 01:31:50 +00:00
|
|
|
})
|
2016-10-25 01:21:42 +00:00
|
|
|
}
|