hasNumericValue.js 1.9 KB

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