-
Notifications
You must be signed in to change notification settings - Fork 482
Expand file tree
/
Copy pathStdlib.res
More file actions
197 lines (165 loc) · 5.07 KB
/
Stdlib.res
File metadata and controls
197 lines (165 loc) · 5.07 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
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
include Stdlib_Global
module Array = Stdlib_Array
module BigInt = Stdlib_BigInt
module Bool = Stdlib_Bool
module Console = Stdlib_Console
module DataView = Stdlib_DataView
module Date = Stdlib_Date
module Dict = Stdlib_Dict
module Exn = Stdlib_Exn
module Error = Stdlib_Error
module Float = Stdlib_Float
module Int = Stdlib_Int
module Intl = Stdlib_Intl
module JsError = Stdlib_JsError
module JsExn = Stdlib_JsExn
module JSON = Stdlib_JSON
module Lazy = Stdlib_Lazy
module List = Stdlib_List
module Math = Stdlib_Math
module Null = Stdlib_Null
module Nullable = Stdlib_Nullable
module Object = Stdlib_Object
module Option = Stdlib_Option
module Ordering = Stdlib_Ordering
module Pair = Stdlib_Pair
module Promise = Stdlib_Promise
module RegExp = Stdlib_RegExp
module Result = Stdlib_Result
module String = Stdlib_String
module Symbol = Stdlib_Symbol
module Type = Stdlib_Type
module Iterable = Stdlib_Iterable
module Iterator = Stdlib_Iterator
module IteratorObject = Stdlib_IteratorObject
module IterableIterator = Stdlib_IterableIterator
module Generator = Stdlib_Generator
module AsyncIterable = Stdlib_AsyncIterable
module AsyncIterator = Stdlib_AsyncIterator
module AsyncIterableIterator = Stdlib_AsyncIterableIterator
module AsyncGenerator = Stdlib_AsyncGenerator
module Map = Stdlib_Map
module WeakMap = Stdlib_WeakMap
module Set = Stdlib_Set
module WeakSet = Stdlib_WeakSet
module ArrayBuffer = Stdlib_ArrayBuffer
module TypedArray = Stdlib_TypedArray
module Float32Array = Stdlib_Float32Array
module Float64Array = Stdlib_Float64Array
module Int8Array = Stdlib_Int8Array
module Int16Array = Stdlib_Int16Array
module Int32Array = Stdlib_Int32Array
module Uint8Array = Stdlib_Uint8Array
module Uint16Array = Stdlib_Uint16Array
module Uint32Array = Stdlib_Uint32Array
module Uint8ClampedArray = Stdlib_Uint8ClampedArray
module BigInt64Array = Stdlib_BigInt64Array
module BigUint64Array = Stdlib_BigUint64Array
// Type aliases for convenience
type date = Date.t
type null<+'a> = Primitive_js_extern.null<'a>
type undefined<+'a> = Primitive_js_extern.undefined<'a>
type nullable<+'a> = Primitive_js_extern.nullable<'a>
@deprecated("Use Lazy.t instead")
type lazy_t<+'a> = Lazy.t<'a>
@deprecated("Use rescript-webapi instead") @val external window: Dom.window = "window"
@deprecated("Use rescript-webapi instead") @val external document: Dom.document = "document"
/**
`globalThis` gives you the host global object (`window` in browsers, `global` in Node, etc.).
You can reach shared globals from any runtime without special checks.
## Examples
**Note:** These are demonstrative examples. In real code, prefer writing your own type-safe bindings.
See [`Bind to Global JS Values`](https://rescript-lang.org/docs/manual/v12.0.0/bind-to-global-js-values).
```rescript
typeof(globalThis["setTimeout"]) == #function
globalThis["myAppName"] = "SuperApp";
globalThis["myAppName"] == "SuperApp"
```
*/
@val external globalThis: {..} = "globalThis"
/**
`import(value)` dynamically import a value or function from a ReScript
module. The import call will return a `promise`, resolving to the dynamically loaded
value.
## Examples
`Array.res` file:
```rescript
@send external indexOf: (array<'a>, 'a) => int = "indexOf"
let indexOfOpt = (arr, item) =>
switch arr->indexOf(item) {
| -1 => None
| index => Some(index)
}
```
In other file you can import the `indexOfOpt` value defined in `Array.res`
```rescript
let main = async () => {
let indexOfOpt = await import(Array.indexOfOpt)
let index = indexOfOpt([1, 2], 2)
Console.log(index)
}
```
Compiles to:
```javascript
async function main() {
var add = await import("./Array.mjs").then(function(m) {
return m.indexOfOpt;
});
var index = indexOfOpt([1, 2], 2);
console.log(index);
}
```
*/
external import: 'a => promise<'a> = "%import"
/**
`panic(message)` throws a JavaScript `Error` prefixed with `Panic!`.
Call it when something went wrong and the program should stop right away.
## Examples
```rescript
let caught = try panic("Invariant violated") catch {
| JsExn(err) => JsExn.message(err)->Option.getOrThrow
}
caught == "Panic! Invariant violated"
```
*/
let panic = JsError.panic
/**
`assertEqual(a, b)` check if `a` is equal `b`. If not throw a panic exception
## Examples
```rescript
list{1, 2}->List.tailExn == list{2}
```
*/
let assertEqual = (a, b) => {
if a != b {
assert(false)
}
}
/**
`null` returns the JavaScript `null` value as a `nullable<'a>`.
Use the `Nullable` helpers to convert it into an `option` or to read the value.
## Examples
```rescript
null->Nullable.toOption == None
```
*/
external null: nullable<'a> = "#null"
/**
`undefined` returns the JavaScript `undefined` value as a `nullable<'a>`.
Use the `Nullable` helpers to convert it into an `option` or to read the value.
## Examples
```rescript
undefined->Nullable.toOption == None
```
*/
external undefined: nullable<'a> = "#undefined"
/**
`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.
It helps you inspect values that come from JavaScript APIs.
## Examples
```rescript
typeof(1) == #number
typeof("a") == #string
```
*/
external typeof: 'a => Type.t = "#typeof"