forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhasNumericValue.js
More file actions
44 lines (41 loc) · 1.38 KB
/
hasNumericValue.js
File metadata and controls
44 lines (41 loc) · 1.38 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
'use strict'
function factory (type, config, load, typed) {
const isNumeric = load(require('./isNumeric'))
/**
* Test whether a value is an numeric value.
*
* Syntax:
*
* math.hasNumericValue(x)
*
* Examples:
*
* math.hasNumericValue(2) // returns true
* math.hasNumericValue(0) // returns true
* math.hasNumericValue(math.bignumber(500)) // returns true
* math.hasNumericValue(math.fraction(4)) // returns true
* math.hasNumericValue(math.complex('2-4i') // returns false
* math.hasNumericValue('3') // returns true
* math.hasNumericValue([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`, `Boolean`, or a `String` containing number. Returns false for other types.
* Throws an error in case of unknown types.
*/
const hasNumericValue = typed('hasNumericValue', {
'string': function (x) {
return x.trim().length > 0 && !isNaN(Number(x))
},
'any': function (x) {
return isNumeric(x)
}
})
return hasNumericValue
}
exports.name = 'hasNumericValue'
exports.factory = factory