1 | import { factory } from '../../utils/factory.js';
|
2 | import { typeOf as _typeOf } from '../../utils/is.js';
|
3 | var name = 'typeOf';
|
4 | var dependencies = ['typed'];
|
5 | export var createTypeOf = /* #__PURE__ */factory(name, dependencies, (_ref) => {
|
6 | var {
|
7 | typed
|
8 | } = _ref;
|
9 |
|
10 | /**
|
11 | * Determine the type of a variable.
|
12 | *
|
13 | * Function `typeOf` recognizes the following types of objects:
|
14 | *
|
15 | * Object | Returns | Example
|
16 | * ---------------------- | ------------- | ------------------------------------------
|
17 | * null | `'null'` | `math.typeOf(null)`
|
18 | * number | `'number'` | `math.typeOf(3.5)`
|
19 | * boolean | `'boolean'` | `math.typeOf(true)`
|
20 | * string | `'string'` | `math.typeOf('hello world')`
|
21 | * Array | `'Array'` | `math.typeOf([1, 2, 3])`
|
22 | * Date | `'Date'` | `math.typeOf(new Date())`
|
23 | * Function | `'Function'` | `math.typeOf(function () {})`
|
24 | * Object | `'Object'` | `math.typeOf({a: 2, b: 3})`
|
25 | * RegExp | `'RegExp'` | `math.typeOf(/a regexp/)`
|
26 | * undefined | `'undefined'` | `math.typeOf(undefined)`
|
27 | * math.BigNumber | `'BigNumber'` | `math.typeOf(math.bignumber('2.3e500'))`
|
28 | * math.Chain | `'Chain'` | `math.typeOf(math.chain(2))`
|
29 | * math.Complex | `'Complex'` | `math.typeOf(math.complex(2, 3))`
|
30 | * math.Fraction | `'Fraction'` | `math.typeOf(math.fraction(1, 3))`
|
31 | * math.Help | `'Help'` | `math.typeOf(math.help('sqrt'))`
|
32 | * math.Help | `'Help'` | `math.typeOf(math.help('sqrt'))`
|
33 | * math.Index | `'Index'` | `math.typeOf(math.index(1, 3))`
|
34 | * math.Matrix | `'Matrix'` | `math.typeOf(math.matrix([[1,2], [3, 4]]))`
|
35 | * math.Range | `'Range'` | `math.typeOf(math.range(0, 10))`
|
36 | * math.ResultSet | `'ResultSet'` | `math.typeOf(math.evaluate('a=2\nb=3'))`
|
37 | * math.Unit | `'Unit'` | `math.typeOf(math.unit('45 deg'))`
|
38 | * math.AccessorNode | `'AccessorNode'` | `math.typeOf(math.parse('A[2]'))`
|
39 | * math.ArrayNode | `'ArrayNode'` | `math.typeOf(math.parse('[1,2,3]'))`
|
40 | * math.AssignmentNode | `'AssignmentNode'` | `math.typeOf(math.parse('x=2'))`
|
41 | * math.BlockNode | `'BlockNode'` | `math.typeOf(math.parse('a=2; b=3'))`
|
42 | * math.ConditionalNode | `'ConditionalNode'` | `math.typeOf(math.parse('x<0 ? -x : x'))`
|
43 | * math.ConstantNode | `'ConstantNode'` | `math.typeOf(math.parse('2.3'))`
|
44 | * math.FunctionAssignmentNode | `'FunctionAssignmentNode'` | `math.typeOf(math.parse('f(x)=x^2'))`
|
45 | * math.FunctionNode | `'FunctionNode'` | `math.typeOf(math.parse('sqrt(4)'))`
|
46 | * math.IndexNode | `'IndexNode'` | `math.typeOf(math.parse('A[2]').index)`
|
47 | * math.ObjectNode | `'ObjectNode'` | `math.typeOf(math.parse('{a:2}'))`
|
48 | * math.ParenthesisNode | `'ParenthesisNode'` | `math.typeOf(math.parse('(2+3)'))`
|
49 | * math.RangeNode | `'RangeNode'` | `math.typeOf(math.parse('1:10'))`
|
50 | * math.SymbolNode | `'SymbolNode'` | `math.typeOf(math.parse('x'))`
|
51 | *
|
52 | * Syntax:
|
53 | *
|
54 | * math.typeOf(x)
|
55 | *
|
56 | * Examples:
|
57 | *
|
58 | * math.typeOf(3.5) // returns 'number'
|
59 | * math.typeOf(math.complex('2-4i')) // returns 'Complex'
|
60 | * math.typeOf(math.unit('45 deg')) // returns 'Unit'
|
61 | * math.typeOf('hello world') // returns 'string'
|
62 | *
|
63 | * @param {*} x The variable for which to test the type.
|
64 | * @return {string} Returns the name of the type. Primitive types are lower case,
|
65 | * non-primitive types are upper-camel-case.
|
66 | * For example 'number', 'string', 'Array', 'Date'.
|
67 | */
|
68 | return typed(name, {
|
69 | any: _typeOf
|
70 | });
|
71 | }); |
\ | No newline at end of file |