Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

number.js 694B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. /**
  3. * `input` type prompt
  4. */
  5. var Input = require('./input');
  6. /**
  7. * Extention of the Input prompt specifically for use with number inputs.
  8. */
  9. class NumberPrompt extends Input {
  10. filterInput(input) {
  11. if (input && typeof input === 'string') {
  12. input = input.trim();
  13. // Match a number in the input
  14. let numberMatch = input.match(/(^-?\d+|^\d+\.\d*|^\d*\.\d+)(e\d+)?$/);
  15. // If a number is found, return that input.
  16. if (numberMatch) {
  17. return Number(numberMatch[0]);
  18. }
  19. }
  20. // If the input was invalid return the default value.
  21. return this.opt.default == null ? NaN : this.opt.default;
  22. }
  23. }
  24. module.exports = NumberPrompt;