FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mathjs/src/utils/is.js at develop · ideatic/mathjs · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ideatic
/
mathjs
Public
forked from
josdejong/mathjs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
mathjs
/
src
/
utils
/
is.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
203 lines (159 loc) · 5.56 KB
Breadcrumbs
mathjs
/
src
/
utils
/
is.js
Copy path
File metadata and controls
203 lines (159 loc) · 5.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// type checks for all known types
//
// note that:
//
// - check by duck-typing on a property like `isUnit`, instead of checking instanceof.
// instanceof cannot be used because that would not allow to pass data from
// one instance of math.js to another since each has it's own instance of Unit.
// - check the `isUnit` property via the constructor, so there will be no
// matches for "fake" instances like plain objects with a property `isUnit`.
// That is important for security reasons.
// - It must not be possible to override the type checks used internally,
// for security reasons, so these functions are not exposed in the expression
// parser.
export
function
isNumber
(
x
)
{
return
typeof
x
===
'number'
}
export
function
isBigNumber
(
x
)
{
return
(
x
&&
x
.
constructor
.
prototype
.
isBigNumber
===
true
)
||
false
}
export
function
isComplex
(
x
)
{
return
(
x
&&
typeof
x
===
'object'
&&
Object
.
getPrototypeOf
(
x
)
.
isComplex
===
true
)
||
false
}
export
function
isFraction
(
x
)
{
return
(
x
&&
typeof
x
===
'object'
&&
Object
.
getPrototypeOf
(
x
)
.
isFraction
===
true
)
||
false
}
export
function
isUnit
(
x
)
{
return
(
x
&&
x
.
constructor
.
prototype
.
isUnit
===
true
)
||
false
}
export
function
isString
(
x
)
{
return
typeof
x
===
'string'
}
export
const
isArray
=
Array
.
isArray
export
function
isMatrix
(
x
)
{
return
(
x
&&
x
.
constructor
.
prototype
.
isMatrix
===
true
)
||
false
}
/**
* Test whether a value is a collection: an Array or Matrix
*
@param
{
*
} x
*
@returns
{
boolean
} isCollection
*/
export
function
isCollection
(
x
)
{
return
Array
.
isArray
(
x
)
||
isMatrix
(
x
)
}
export
function
isDenseMatrix
(
x
)
{
return
(
x
&&
x
.
isDenseMatrix
&&
x
.
constructor
.
prototype
.
isMatrix
===
true
)
||
false
}
export
function
isSparseMatrix
(
x
)
{
return
(
x
&&
x
.
isSparseMatrix
&&
x
.
constructor
.
prototype
.
isMatrix
===
true
)
||
false
}
export
function
isRange
(
x
)
{
return
(
x
&&
x
.
constructor
.
prototype
.
isRange
===
true
)
||
false
}
export
function
isIndex
(
x
)
{
return
(
x
&&
x
.
constructor
.
prototype
.
isIndex
===
true
)
||
false
}
export
function
isBoolean
(
x
)
{
return
typeof
x
===
'boolean'
}
export
function
isResultSet
(
x
)
{
return
(
x
&&
x
.
constructor
.
prototype
.
isResultSet
===
true
)
||
false
}
export
function
isHelp
(
x
)
{
return
(
x
&&
x
.
constructor
.
prototype
.
isHelp
===
true
)
||
false
}
export
function
isFunction
(
x
)
{
return
typeof
x
===
'function'
}
export
function
isDate
(
x
)
{
return
x
instanceof
Date
}
export
function
isRegExp
(
x
)
{
return
x
instanceof
RegExp
}
export
function
isObject
(
x
)
{
return
!
!
(
x
&&
typeof
x
===
'object'
&&
x
.
constructor
===
Object
&&
!
isComplex
(
x
)
&&
!
isFraction
(
x
)
)
}
export
function
isNull
(
x
)
{
return
x
===
null
}
export
function
isUndefined
(
x
)
{
return
x
===
undefined
}
export
function
isAccessorNode
(
x
)
{
return
(
x
&&
x
.
isAccessorNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isArrayNode
(
x
)
{
return
(
x
&&
x
.
isArrayNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isAssignmentNode
(
x
)
{
return
(
x
&&
x
.
isAssignmentNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isBlockNode
(
x
)
{
return
(
x
&&
x
.
isBlockNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isConditionalNode
(
x
)
{
return
(
x
&&
x
.
isConditionalNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isConstantNode
(
x
)
{
return
(
x
&&
x
.
isConstantNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isFunctionAssignmentNode
(
x
)
{
return
(
x
&&
x
.
isFunctionAssignmentNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isFunctionNode
(
x
)
{
return
(
x
&&
x
.
isFunctionNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isIndexNode
(
x
)
{
return
(
x
&&
x
.
isIndexNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isNode
(
x
)
{
return
(
x
&&
x
.
isNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isObjectNode
(
x
)
{
return
(
x
&&
x
.
isObjectNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isOperatorNode
(
x
)
{
return
(
x
&&
x
.
isOperatorNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isParenthesisNode
(
x
)
{
return
(
x
&&
x
.
isParenthesisNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isRangeNode
(
x
)
{
return
(
x
&&
x
.
isRangeNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isSymbolNode
(
x
)
{
return
(
x
&&
x
.
isSymbolNode
===
true
&&
x
.
constructor
.
prototype
.
isNode
===
true
)
||
false
}
export
function
isChain
(
x
)
{
return
(
x
&&
x
.
constructor
.
prototype
.
isChain
===
true
)
||
false
}
export
function
typeOf
(
x
)
{
const
t
=
typeof
x
if
(
t
===
'object'
)
{
// JavaScript types
if
(
x
===
null
)
return
'null'
if
(
Array
.
isArray
(
x
)
)
return
'Array'
if
(
x
instanceof
Date
)
return
'Date'
if
(
x
instanceof
RegExp
)
return
'RegExp'
// math.js types
if
(
isBigNumber
(
x
)
)
return
'BigNumber'
if
(
isComplex
(
x
)
)
return
'Complex'
if
(
isFraction
(
x
)
)
return
'Fraction'
if
(
isMatrix
(
x
)
)
return
'Matrix'
if
(
isUnit
(
x
)
)
return
'Unit'
if
(
isIndex
(
x
)
)
return
'Index'
if
(
isRange
(
x
)
)
return
'Range'
if
(
isResultSet
(
x
)
)
return
'ResultSet'
if
(
isNode
(
x
)
)
return
x
.
type
if
(
isChain
(
x
)
)
return
'Chain'
if
(
isHelp
(
x
)
)
return
'Help'
return
'Object'
}
if
(
t
===
'function'
)
return
'Function'
return
t
// can be 'string', 'number', 'boolean', ...
}
Back
|
FazBrowse Home
|
New Git URL