isNumeric.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { deepMap } from '../../utils/collection.js';
  2. import { factory } from '../../utils/factory.js';
  3. var name = 'isNumeric';
  4. var dependencies = ['typed'];
  5. export var createIsNumeric = /* #__PURE__ */factory(name, dependencies, _ref => {
  6. var {
  7. typed
  8. } = _ref;
  9. /**
  10. * Test whether a value is an numeric value.
  11. *
  12. * The function is evaluated element-wise in case of Array or Matrix input.
  13. *
  14. * Syntax:
  15. *
  16. * math.isNumeric(x)
  17. *
  18. * Examples:
  19. *
  20. * math.isNumeric(2) // returns true
  21. * math.isNumeric('2') // returns false
  22. * math.hasNumericValue('2') // returns true
  23. * math.isNumeric(0) // returns true
  24. * math.isNumeric(math.bignumber(500)) // returns true
  25. * math.isNumeric(math.fraction(4)) // returns true
  26. * math.isNumeric(math.complex('2-4i')) // returns false
  27. * math.isNumeric([2.3, 'foo', false]) // returns [true, false, true]
  28. *
  29. * See also:
  30. *
  31. * isZero, isPositive, isNegative, isInteger, hasNumericValue
  32. *
  33. * @param {*} x Value to be tested
  34. * @return {boolean} Returns true when `x` is a `number`, `BigNumber`,
  35. * `Fraction`, or `boolean`. Returns false for other types.
  36. * Throws an error in case of unknown types.
  37. */
  38. return typed(name, {
  39. 'number | BigNumber | Fraction | boolean': () => true,
  40. 'Complex | Unit | string | null | undefined | Node': () => false,
  41. 'Array | Matrix': typed.referToSelf(self => x => deepMap(x, self))
  42. });
  43. });