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