UNPKG

util-ex

Version:

Browser-friendly enhanced util fully compatible with standard node.js

25 lines (23 loc) 767 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; exports.isFloatStr = isFloatStr; const float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/; /** * Checks if a string represents a valid floating point number. * @param {string} str The string to test. * @returns {boolean} `true` if the string represents a valid floating point number, `false` otherwise. * @example * isFloatStr('3.14'); // returns true * isFloatStr('-0.5'); // returns true * isFloatStr('2.718e0'); // returns true * isFloatStr('2.718e-2'); // returns true * isFloatStr('abc'); // returns false */ function isFloatStr(str) { return str !== '' && float.test(str); } ; var _default = exports.default = isFloatStr;