hasNumericValue.js (1618B)
1 import { factory } from '../../utils/factory.js'; 2 var name = 'hasNumericValue'; 3 var dependencies = ['typed', 'isNumeric']; 4 export var createHasNumericValue = /* #__PURE__ */factory(name, dependencies, _ref => { 5 var { 6 typed, 7 isNumeric 8 } = _ref; 9 10 /** 11 * Test whether a value is an numeric value. 12 * 13 * In case of a string, true is returned if the string contains a numeric value. 14 * 15 * Syntax: 16 * 17 * math.hasNumericValue(x) 18 * 19 * Examples: 20 * 21 * math.hasNumericValue(2) // returns true 22 * math.hasNumericValue('2') // returns true 23 * math.isNumeric('2') // returns false 24 * math.hasNumericValue(0) // returns true 25 * math.hasNumericValue(math.bignumber(500)) // returns true 26 * math.hasNumericValue(math.fraction(4)) // returns true 27 * math.hasNumericValue(math.complex('2-4i') // returns false 28 * math.hasNumericValue([2.3, 'foo', false]) // returns [true, false, true] 29 * 30 * See also: 31 * 32 * isZero, isPositive, isNegative, isInteger, isNumeric 33 * 34 * @param {*} x Value to be tested 35 * @return {boolean} Returns true when `x` is a `number`, `BigNumber`, 36 * `Fraction`, `Boolean`, or a `String` containing number. Returns false for other types. 37 * Throws an error in case of unknown types. 38 */ 39 return typed(name, { 40 string: function string(x) { 41 return x.trim().length > 0 && !isNaN(Number(x)); 42 }, 43 any: function any(x) { 44 return isNumeric(x); 45 } 46 }); 47 });