UNPKG

hubot-command-mapper

Version:
40 lines (39 loc) 1.41 kB
import { FractionStyle } from "./FractionStyle.mjs"; import { NumberParameter } from "./NumberParameter.mjs"; import { NumberStyle } from "./NumberStyle.mjs"; export class FractionParameter extends NumberParameter { style; /** * Captures the sign (when specified), both numbers of the * fraction and the separator. * * @readonly * @memberof FractionParameter */ get regex() { var r = super.regex + "("; if (this.style == FractionStyle.Both) { r += "(.|,)"; } else if (this.style == FractionStyle.Comma) { r += ","; } else if (this.style == FractionStyle.Dot) { r += "."; } r += "\\d+)?"; return r; } /** *Creates an instance of FractionParameter. * @param {string} name The name of the parameter. * @param {any} [defaultValue=null] When a value is given, the parameter becomes optional. * @param {NumberStyle} [numberStyle=NumberStyle.Both] The style of the number (positive, negative, both). * @param {FractionStyle} [style=FractionStyle.Both] The style of the fraction (dot, comma or both). * @memberof FractionParameter */ constructor(name, defaultValue = null, numberStyle = NumberStyle.Both, style = FractionStyle.Both) { super(name, defaultValue, numberStyle); this.style = style; } }