1234567891011121314151617181920212223242526272829 |
- 'use strict';
- const Input = require('./input');
- class NumberPrompt extends Input {
- filterInput(input) {
- if (input && typeof input === 'string') {
- input = input.trim();
-
- const numberMatch = input.match(/(^-?\d+|^-?\d+\.\d*|^\d*\.\d+)(e\d+)?$/);
-
- if (numberMatch) {
- return Number(numberMatch[0]);
- }
- }
-
- return this.opt.default == null ? NaN : this.opt.default;
- }
- }
- module.exports = NumberPrompt;
|