isFloat.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isFloat;
  6. exports.locales = void 0;
  7. var _assertString = _interopRequireDefault(require("./util/assertString"));
  8. var _alpha = require("./alpha");
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function isFloat(str, options) {
  11. (0, _assertString.default)(str);
  12. options = options || {};
  13. var float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? _alpha.decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
  14. if (str === '' || str === '.' || str === '-' || str === '+') {
  15. return false;
  16. }
  17. var value = parseFloat(str.replace(',', '.'));
  18. return float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
  19. }
  20. var locales = Object.keys(_alpha.decimal);
  21. exports.locales = locales;