isNumeric.js 1.9 KB

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