in src/templates/custom.ts [61:120]
_processOptions() {
if (!this.state.options.length) {
if (this.defaultValue !== '') {
throw new SyntaxError(
'cannot define default value without any options'
);
}
return;
}
const newOptions = [];
const queryParts = [];
let hasAll = false;
for (let i = 0; i < this.state.options.length; i++) {
const option = this.state.options[i];
const isObject =
typeof option === 'object' && option.constructor === Object;
const opt = isObject
? option
: {
text: option,
value: option,
};
if (opt.value === DEFAULT_VARIABLE_ALL) {
if (hasAll) {
continue;
}
hasAll = true;
}
newOptions.push(opt);
const valueWithEscapedCommas = String(opt.value).replace(
/,/g,
'\\,'
);
queryParts.push(`${opt.text} : ${valueWithEscapedCommas}`);
}
if (this.defaultValue !== '') {
const defaultOption = newOptions.find(
(option) => option.value === this.defaultValue
);
if (!defaultOption) {
throw new SyntaxError(
'default value not found in options list'
);
}
this.state.current = defaultOption;
} else if (
(!this.state.current ||
Object.keys(this.state.current).length === 0) &&
!this.state.includeAll
) {
this.state.current = newOptions[0];
}
this.state.options = newOptions;
this.state.query = queryParts.join(', ');
}