hubot-command-mapper
Version:
Helps with mapping tools and commands to Hubot.
36 lines (35 loc) • 1.09 kB
JavaScript
import { escapeRegExp } from "../../utils/regex.mjs";
import { ParameterBase } from "./ParameterBase.mjs";
/**
* Parameter that has a fixed set of values. Remember all values
* are not case sensitive.
*
* @export
* @class ChoiceParameter
* @extends {ParameterBase}
*/
export class ChoiceParameter extends ParameterBase {
values;
defaultValue;
/**
* Will only capture the choices.
*
* @readonly
* @memberof ChoiceParameter
*/
get regex() {
return `${this.values.map(v => escapeRegExp(v)).join("|")}`;
}
/**
* Creates an instance of ChoiceParameter.
* @param {string} name The name of the parameter. Can be used to identify the parameter value as well.
* @param {string[]} values The array of possible values.
* @param {any} [defaultValue=null] When a value is given, the parameter becomes optional.
* @memberof ChoiceParameter
*/
constructor(name, values, defaultValue = null) {
super(name, defaultValue);
this.values = values;
this.defaultValue = defaultValue;
}
}