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