isFloat.js 730 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isFloat;
  6. var _assertString = require('./util/assertString');
  7. var _assertString2 = _interopRequireDefault(_assertString);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. var float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/;
  10. function isFloat(str, options) {
  11. (0, _assertString2.default)(str);
  12. options = options || {};
  13. if (str === '' || str === '.') {
  14. return false;
  15. }
  16. return float.test(str) && (!options.hasOwnProperty('min') || str >= options.min) && (!options.hasOwnProperty('max') || str <= options.max);
  17. }
  18. module.exports = exports['default'];