hubot-command-mapper
Version:
Helps with mapping tools and commands to Hubot.
62 lines (61 loc) • 1.98 kB
JavaScript
import { ParameterBase } from "./ParameterBase.mjs";
/**
* Uses a regular expression to capture the value.
*
* @export
* @class RegExStringParameter
* @extends {ParameterBase}
*/
export class RegExStringParameter extends ParameterBase {
regexString;
defaultValue;
/**
* Uses the regexString to capture the value. Values can also be written
* between quotes.
*
* @readonly
* @memberof RegExStringParameter
*/
get regex() {
var x = this.regexString;
return `"${x}[^"]*"|'${x}[^']*'|${x}[^ ]*`;
}
/**
* Creates an instance of RegExStringParameter.
* @param {string} name The name of the parameter.
* @param {string} regexString This regex string will be added to the regex that captures the value.
* @param {any} [defaultValue=null] When a value is given, the parameter becomes optional.
* @memberof RegExStringParameter
*/
constructor(name, regexString, defaultValue = null) {
super(name, defaultValue);
this.regexString = regexString;
this.defaultValue = defaultValue;
}
}
export class RegExParameter extends ParameterBase {
regexString;
defaultValue;
/**
* Uses the regexString to capture the value. Values can also be written
* between quotes.
*
* @readonly
* @memberof RegExStringParameter
*/
get regex() {
return this.regexString;
}
/**
* Creates an instance of RegExStringParameter.
* @param {string} name The name of the parameter.
* @param {string} regexString This regex string will be added to the regex that captures the value.
* @param {any} [defaultValue=null] When a value is given, the parameter becomes optional.
* @memberof RegExStringParameter
*/
constructor(name, regexString, defaultValue = null) {
super(name, defaultValue);
this.regexString = regexString;
this.defaultValue = defaultValue;
}
}