1
- ( * Copyright (C) 2015-2016 Bloomberg Finance L.P.
1
+ / * Copyright (C) 2015-2016 Bloomberg Finance L.P.
2
2
*
3
3
* This program is free software: you can redistribute it and/or modify
4
4
* it under the terms of the GNU Lesser General Public License as published by
20
20
*
21
21
* You should have received a copy of the GNU Lesser General Public License
22
22
* along with this program; if not, write to the Free Software
23
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
23
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
24
25
- [ @@@ config {flags = [| " -unboxed-types" ; " -w" ; " -49" |]}]
26
- ( * DESIGN:
25
+ @@ config ( {flags : [ "-unboxed-types" , "-w" , "-49" ]})
26
+ @@ ocaml.text ( / * DESIGN:
27
27
- It does not have any code, all its code will be inlined so that
28
28
there will never be
29
29
{[ require('js')]}
30
30
- Its interface should be minimal
31
- *)
31
+ */
32
32
33
- (* *
33
+ "
34
34
The Js module mostly contains ReScript bindings to _standard JavaScript APIs_
35
35
like [console.log](https://developer.mozilla.org/en-US/docs/Web/API/Console/log),
36
36
or the JavaScript
@@ -57,234 +57,233 @@ In the meantime, there are several options for dealing with the data-last APIs:
57
57
58
58
```rescript
59
59
/* Js.String (data-last API used with pipe last operator) */
60
- Js.log("2019-11-10" |> Js.String.split("- "))
61
- Js.log("ReScript" |> Js.String.startsWith("Re"))
60
+ Js.log(\ " 2019-11-10\ " |> Js.String.split(\" - \ " ))
61
+ Js.log(\ " ReScript\ " |> Js.String.startsWith(\ " Re\ " ))
62
62
63
63
/* Js.String (data-last API used with pipe first operator) */
64
- Js.log("2019-11-10"->Js.String.split("- ", _))
65
- Js.log("ReScript"->Js.String.startsWith("Re", _))
64
+ Js.log(\ " 2019-11-10\ " ->Js.String.split(\" - \ " , _))
65
+ Js.log(\ " ReScript\ " ->Js.String.startsWith(\ " Re\ " , _))
66
66
67
67
/* Js.String (data-last API used without any piping) */
68
- Js.log(Js.String.split("- ", "2019-11-10"))
69
- Js.log(Js.String.startsWith("Re", "ReScript"))
68
+ Js.log(Js.String.split(\" - \ " , \ " 2019-11-10\ " ))
69
+ Js.log(Js.String.startsWith(\ " Re\ " , \ " ReScript\ " ))
70
70
```
71
71
## Js.Xxx2 Modules
72
72
73
73
Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latters are old modules.
74
- * )
74
+ " )
75
75
76
- type 'a t = < .. > as 'a
77
- (* * JS object type *)
76
+ @ ocaml.doc ( " JS object type " )
77
+ type t < 'a > = { .. } as 'a
78
78
79
79
module MapperRt = Js_mapperRt
80
80
81
- module Internal = struct
82
- external opaqueFullApply : 'a - > 'a = " %uncurried_apply"
81
+ module Internal = {
82
+ external opaqueFullApply : 'a = > 'a = "%uncurried_apply"
83
83
84
- ( * Use opaque instead of [._n] to prevent some optimizations happening *)
85
- external run : ((unit - > 'a )[ @ bs]) - > 'a = " #run"
86
- external opaque : 'a - > 'a = " %opaque"
87
- end
84
+ / * Use opaque instead of [._n] to prevent some optimizations happening */
85
+ external run : ((. unit ) = > 'a ) = > 'a = "#run"
86
+ external opaque : 'a = > 'a = "%opaque"
87
+ }
88
88
89
- (* */* * )
89
+ @@ ocaml.text ( "/*" )
90
90
91
- (* *
91
+ @ ocaml.doc ( "
92
92
Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t.
93
- *)
94
- type +'a null = Value of 'a | Null [@ as null ] [@@ unboxed]
93
+ " )
94
+ @unboxed
95
+ type null <+ 'a > = Value ('a ) | @as (null ) Null
95
96
96
- type +'a undefined
97
- (* *
97
+ @ocaml.doc ("
98
98
A value of this type can be either undefined or 'a. This type is equivalent to Js.Undefined.t.
99
- *)
99
+ " )
100
+ type undefined <+ 'a >
100
101
101
- type +'a nullable = Value of 'a | Null [@ as null ] | Undefined [@ as undefined ]
102
- [@@ unboxed]
102
+ @unboxed type nullable <+ 'a > = Value ('a ) | @as (null ) Null | @as (undefined ) Undefined
103
103
104
- (* *
104
+ @@ ocaml.text ( "
105
105
A value of this type can be undefined, null or 'a. This type is equivalent to Js.Null_undefined.t.
106
- * )
106
+ " )
107
107
108
- type +'a null_undefined = 'a nullable
108
+ type null_undefined < + 'a > = nullable < 'a >
109
109
110
- external toOption : 'a nullable -> 'a option = " #nullable_to_opt"
111
- external undefinedToOption : 'a undefined -> 'a option = " #undefined_to_opt"
112
- external nullToOption : 'a null -> 'a option = " #null_to_opt"
113
- external isNullable : 'a nullable - > bool = " #is_nullable"
114
- external import : 'a -> 'a promise = " #import"
110
+ external toOption : nullable < 'a > => option < 'a > = "#nullable_to_opt"
111
+ external undefinedToOption : undefined < 'a > => option < 'a > = "#undefined_to_opt"
112
+ external nullToOption : null < 'a > => option < 'a > = "#null_to_opt"
113
+ external isNullable : nullable < 'a > = > bool = "#is_nullable"
114
+ external import : 'a => promise < 'a > = "#import"
115
115
116
- external testAny : 'a -> bool = " #is_nullable "
117
- (* * The same as {!test} except that it is more permissive on the types of input *)
116
+ @ ocaml.doc ( " The same as {!test} except that it is more permissive on the types of input " )
117
+ external testAny : 'a => bool = "#is_nullable"
118
118
119
- type (+'a, +'e) promise
120
- (* *
119
+ @ocaml.doc ("
121
120
The promise type, defined here for interoperation across packages.
122
- *)
121
+ " )
122
+ type promise <+ 'a , + 'e >
123
123
124
- external null : 'a null = " #null"
125
- (* *
124
+ @ocaml.doc ("
126
125
The same as empty in `Js.Null`. Compiles to `null`.
127
- *)
126
+ " )
127
+ external null : null <'a > = "#null"
128
128
129
- external undefined : 'a undefined = " #undefined"
130
- (* *
129
+ @ocaml.doc ("
131
130
The same as empty `Js.Undefined`. Compiles to `undefined`.
132
- *)
131
+ " )
132
+ external undefined : undefined <'a > = "#undefined"
133
133
134
- external typeof : 'a -> string = " #typeof"
135
- (* *
134
+ @ocaml.doc ("
136
135
`typeof x` will be compiled as `typeof x` in JS. Please consider functions in
137
136
`Js.Types` for a type safe way of reflection.
138
- *)
137
+ " )
138
+ external typeof : 'a => string = "#typeof"
139
139
140
- external log : 'a -> unit = " log"
141
- [@@ val] [@@ scope "console" ]
142
- (* * Equivalent to console.log any value. *)
140
+ @val @scope ("console" ) @ocaml.doc (" Equivalent to console.log any value. " )
141
+ external log : 'a => unit = "log"
143
142
144
- external log2 : 'a -> 'b - > unit = " log" [ @@ val] [ @@ scope "console" ]
145
- external log3 : 'a -> 'b -> 'c - > unit = " log" [ @@ val] [ @@ scope "console" ]
143
+ @ val @ scope ( "console" ) external log2 : ( 'a , 'b ) = > unit = "log"
144
+ @ val @ scope ( "console" ) external log3 : ( 'a , 'b , 'c ) = > unit = "log"
146
145
147
- external log4 : 'a -> 'b -> 'c -> 'd - > unit = " log" [ @@ val] [ @@ scope "console" ]
146
+ @ val @ scope ( "console" ) external log4 : ( 'a , 'b , 'c , 'd ) = > unit = "log"
148
147
149
- external logMany : 'a array -> unit = " log"
150
- [@@ val] [@@ scope "console" ] [@@ variadic]
151
- (* * A convenience function to console.log more than 4 arguments *)
148
+ @val
149
+ @scope ("console" )
150
+ @variadic
151
+ @ocaml.doc (" A convenience function to console.log more than 4 arguments " )
152
+ external logMany : array <'a > => unit = "log"
152
153
153
- external eqNull : 'a -> 'a null - > bool = " %bs_equal_null"
154
- external eqUndefined : 'a -> 'a undefined - > bool = " %bs_equal_undefined"
155
- external eqNullable : 'a -> 'a nullable - > bool = " %bs_equal_nullable"
154
+ external eqNull : ( 'a , null < 'a >) = > bool = "%bs_equal_null"
155
+ external eqUndefined : ( 'a , undefined < 'a >) = > bool = "%bs_equal_undefined"
156
+ external eqNullable : ( 'a , nullable < 'a >) = > bool = "%bs_equal_nullable"
156
157
157
- (* * ## Operators * )
158
+ @@ ocaml.text ( " ## Operators " )
158
159
159
- external unsafe_lt : 'a -> 'a -> bool = " #unsafe_lt"
160
- (* *
160
+ @ocaml.doc ("
161
161
`unsafe_lt(a, b)` will be compiled as `a < b`.
162
162
It is marked as unsafe, since it is impossible
163
163
to give a proper semantics for comparision which applies to any type
164
- *)
164
+ " )
165
+ external unsafe_lt : ('a , 'a ) => bool = "#unsafe_lt"
165
166
166
- external unsafe_le : 'a -> 'a -> bool = " #unsafe_le"
167
- (* *
167
+ @ocaml.doc ("
168
168
`unsafe_le(a, b)` will be compiled as `a <= b`.
169
169
See also `Js.unsafe_lt`.
170
- *)
170
+ " )
171
+ external unsafe_le : ('a , 'a ) => bool = "#unsafe_le"
171
172
172
- external unsafe_gt : 'a -> 'a -> bool = " #unsafe_gt"
173
- (* *
173
+ @ocaml.doc ("
174
174
`unsafe_gt(a, b)` will be compiled as `a > b`.
175
175
See also `Js.unsafe_lt`.
176
- *)
176
+ " )
177
+ external unsafe_gt : ('a , 'a ) => bool = "#unsafe_gt"
177
178
178
- external unsafe_ge : 'a -> 'a -> bool = " #unsafe_ge"
179
- (* *
179
+ @ocaml.doc ("
180
180
`unsafe_ge(a, b)` will be compiled as `a >= b`.
181
181
See also `Js.unsafe_lt`.
182
- *)
182
+ " )
183
+ external unsafe_ge : ('a , 'a ) => bool = "#unsafe_ge"
183
184
184
- (* * ## Nested Modules * )
185
+ @@ ocaml.text ( " ## Nested Modules " )
185
186
187
+ @ocaml.doc (" Provide utilities for `Js.null<'a>` " )
186
188
module Null = Js_null
187
- (* * Provide utilities for `Js.null<'a>` *)
188
189
190
+ @ocaml.doc (" Provide utilities for `Js.undefined<'a>` " )
189
191
module Undefined = Js_undefined
190
- (* * Provide utilities for `Js.undefined<'a>` *)
191
192
193
+ @ocaml.doc (" Provide utilities for `Js.null_undefined` " )
192
194
module Nullable = Js_null_undefined
193
- (* * Provide utilities for `Js.null_undefined` *)
194
195
195
- module Null_undefined =
196
- Js_null_undefined
197
- [@ deprecated " Please use `Js.Nullable`" ]
196
+ module Null_undefined = Js_null_undefined
198
197
198
+ @ocaml.doc (" Provide utilities for dealing with Js exceptions " )
199
199
module Exn = Js_exn
200
- (* * Provide utilities for dealing with Js exceptions *)
201
200
201
+ @ocaml.doc (" Provide bindings to JS array" )
202
202
module Array = Js_array
203
- (* * Provide bindings to JS array*)
204
203
204
+ @ocaml.doc (" Provide bindings to JS array" )
205
205
module Array2 = Js_array2
206
- (* * Provide bindings to JS array*)
207
206
207
+ @ocaml.doc (" Provide bindings to JS string " )
208
208
module String = Js_string
209
- (* * Provide bindings to JS string *)
210
209
210
+ @ocaml.doc (" Provide bindings to JS string " )
211
211
module String2 = Js_string2
212
- (* * Provide bindings to JS string *)
213
212
213
+ @ocaml.doc (" Provide bindings to JS regex expression " )
214
214
module Re = Js_re
215
- (* * Provide bindings to JS regex expression *)
216
215
216
+ @ocaml.doc (" Provide bindings to JS Promise " )
217
217
module Promise = Js_promise
218
- (* * Provide bindings to JS Promise *)
219
218
219
+ @ocaml.doc (" Provide bindings to JS Promise " )
220
220
module Promise2 = Js_promise2
221
- (* * Provide bindings to JS Promise *)
222
221
222
+ @ocaml.doc (" Provide bindings for JS Date " )
223
223
module Date = Js_date
224
- (* * Provide bindings for JS Date *)
225
224
225
+ @ocaml.doc (" Provide utilities for JS dictionary object " )
226
226
module Dict = Js_dict
227
- (* * Provide utilities for JS dictionary object *)
228
227
228
+ @ocaml.doc (" Provide bindings to JS global functions in global namespace" )
229
229
module Global = Js_global
230
- (* * Provide bindings to JS global functions in global namespace*)
231
230
231
+ @ocaml.doc (" Provide utilities for json " )
232
232
module Json = Js_json
233
- (* * Provide utilities for json *)
234
233
234
+ @ocaml.doc (" Provide bindings for JS `Math` object " )
235
235
module Math = Js_math
236
- (* * Provide bindings for JS `Math` object *)
237
236
237
+ @ocaml.doc (" Provide utilities for `Js.t` " )
238
238
module Obj = Js_obj
239
- (* * Provide utilities for `Js.t` *)
240
239
240
+ @ocaml.doc (" Provide bindings for JS typed array " )
241
241
module Typed_array = Js_typed_array
242
- (* * Provide bindings for JS typed array *)
243
242
243
+ @ocaml.doc (" Provide bindings for JS typed array " )
244
244
module TypedArray2 = Js_typed_array2
245
- (* * Provide bindings for JS typed array *)
246
245
246
+ @ocaml.doc (" Provide utilities for manipulating JS types " )
247
247
module Types = Js_types
248
- (* * Provide utilities for manipulating JS types *)
249
248
249
+ @ocaml.doc (" Provide utilities for JS float " )
250
250
module Float = Js_float
251
- (* * Provide utilities for JS float *)
252
251
252
+ @ocaml.doc (" Provide utilities for int " )
253
253
module Int = Js_int
254
- (* * Provide utilities for int *)
255
254
255
+ @ocaml.doc (" Provide utilities for bigint " )
256
256
module BigInt = Js_bigint
257
- (* * Provide utilities for bigint *)
258
257
258
+ @ocaml.doc (" Provide utilities for File " )
259
259
module File = Js_file
260
- (* * Provide utilities for File *)
261
260
261
+ @ocaml.doc (" Provide utilities for Blob " )
262
262
module Blob = Js_blob
263
- (* * Provide utilities for Blob *)
264
263
264
+ @ocaml.doc (" Provide utilities for option " )
265
265
module Option = Js_option
266
- (* * Provide utilities for option *)
267
266
267
+ @ocaml.doc (" Define the interface for result " )
268
268
module Result = Js_result
269
- (* * Define the interface for result *)
270
269
270
+ @ocaml.doc (" Provide utilities for list " )
271
271
module List = Js_list
272
- (* * Provide utilities for list *)
273
272
273
+ @ocaml.doc (" Provides bindings for JS Vector " )
274
274
module Vector = Js_vector
275
- (* * Provides bindings for JS Vector *)
276
275
276
+ @ocaml.doc (" Provides bindings for console " )
277
277
module Console = Js_console
278
- (* * Provides bindings for console *)
279
278
279
+ @ocaml.doc (" Provides bindings for ES6 Set " )
280
280
module Set = Js_set
281
- (* * Provides bindings for ES6 Set *)
282
281
282
+ @ocaml.doc (" Provides bindings for ES6 WeakSet " )
283
283
module WeakSet = Js_weakset
284
- (* * Provides bindings for ES6 WeakSet *)
285
284
285
+ @ocaml.doc (" Provides bindings for ES6 Map " )
286
286
module Map = Js_map
287
- (* * Provides bindings for ES6 Map *)
288
287
288
+ @ocaml.doc (" Provides bindings for ES6 WeakMap " )
289
289
module WeakMap = Js_weakmap
290
- (* * Provides bindings for ES6 WeakMap *)
0 commit comments