simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

hasNumericValue.js (1825B)


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