(str, options)
| 3 | import { decimal } from './alpha'; |
| 4 | |
| 5 | export default function isFloat(str, options) { |
| 6 | assertString(str); |
| 7 | options = options || {}; |
| 8 | const float = new RegExp(`^(?:[-+])?(?:[0-9]+)?(?:\\${options.locale ? decimal[options.locale] : '.'}[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$`); |
| 9 | if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') { |
| 10 | return false; |
| 11 | } |
| 12 | const value = parseFloat(str.replace(',', '.')); |
| 13 | return float.test(str) && |
| 14 | (!options.hasOwnProperty('min') || isNullOrUndefined(options.min) || value >= options.min) && |
| 15 | (!options.hasOwnProperty('max') || isNullOrUndefined(options.max) || value <= options.max) && |
| 16 | (!options.hasOwnProperty('lt') || isNullOrUndefined(options.lt) || value < options.lt) && |
| 17 | (!options.hasOwnProperty('gt') || isNullOrUndefined(options.gt) || value > options.gt); |
| 18 | } |
| 19 | |
| 20 | export const locales = Object.keys(decimal); |
no test coverage detected