frontend/.pnpm-store/v3/files/d1/f20bc708f2252e67af224c99545c198561d222eacac784c0e113a474e4f772637ef68253dc57877ed42682107f34f6a04092ab99bed58139ab7de27ad0145e

27 lines
668 B
Plaintext

/**
* `input` type prompt
*/
import Input from './input.js';
/**
* Extention of the Input prompt specifically for use with number inputs.
*/
export default class NumberPrompt extends Input {
filterInput(input) {
if (input && typeof input === 'string') {
input = input.trim();
// Match a number in the input
const numberMatch = input.match(/(^-?\d+|^-?\d+\.\d*|^\d*\.\d+)(e\d+)?$/);
// If a number is found, return that input.
if (numberMatch) {
return Number(numberMatch[0]);
}
}
// If the input was invalid return the default value.
return this.opt.default == null ? NaN : this.opt.default;
}
}