1
+ /***
2
+ Utilities for classifying the type of JavaScript values at runtime.
3
+ */
4
+
5
+ /**
6
+ The possible types of JavaScript values.
7
+ */
1
8
type t = [#undefined | #object | #boolean | #number | #bigint | #string | #symbol | #function]
2
9
10
+ /**
11
+ `typeof(someValue)`
12
+
13
+ Returns the underlying JavaScript type of any runtime value.
14
+
15
+ See [`typeof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) on MDN.
16
+
17
+ ## Examples
18
+ ```rescript
19
+ Console.log(Type.typeof("Hello")) // Logs "string" to the console.
20
+
21
+ let someVariable = true
22
+
23
+ switch someVariable->Type.typeof {
24
+ | #boolean => Console.log("This is a bool, yay!")
25
+ | _ => Console.log("Oh, not a bool sadly...")
26
+ }
27
+ ```
28
+ */
3
29
external typeof: 'a => t = "#typeof"
4
30
5
31
module Classify: {
32
+ /***
33
+ Classifies JavaScript runtime values.
34
+ */
35
+
36
+ /**
37
+ An abstract type representing a JavaScript function.
38
+
39
+ See [`function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) on MDN.
40
+ */
6
41
type function
42
+
43
+ /**
44
+ An abstract type representing a JavaScript object.
45
+
46
+ See [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) on MDN.
47
+ */
7
48
type object
49
+
50
+ /**
51
+ An abstract type representing a JavaScript symbol.
52
+
53
+ See [`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) on MDN.
54
+ */
8
55
type symbol
9
56
57
+ /**
58
+ The type representing a classified JavaScript value.
59
+ */
10
60
type t =
11
61
| Bool(bool)
12
62
| Null
@@ -17,5 +67,17 @@ module Classify: {
17
67
| Function(function)
18
68
| Symbol(symbol)
19
69
70
+ /**
71
+ `classify(anyValue)`
72
+ Classifies a JavaScript value.
73
+
74
+ ## Examples
75
+ ```rescript
76
+ switch %raw(`null`)->Type.Classify.classify {
77
+ | Null => Console.log("Yup, that's null.")
78
+ | _ => Console.log("This doesn't actually appear to be null...")
79
+ }
80
+ ```
81
+ */
20
82
let classify: 'a => t
21
83
}
0 commit comments