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 695B

1234567891011121314151617181920212223242526272829
  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;