1- ( * Copyright (C) 2015-2016 Bloomberg Finance L.P.
1+ / * Copyright (C) 2015-2016 Bloomberg Finance L.P.
22 *
33 * This program is free software: you can redistribute it and/or modify
44 * it under the terms of the GNU Lesser General Public License as published by
2020 *
2121 * You should have received a copy of the GNU Lesser General Public License
2222 * 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. */
2424
25- [ @@@ config {flags = [| " -unboxed-types" ; " -w" ; " -49" |]}]
26- ( * DESIGN:
25+ @@ config ( {flags : [ "-unboxed-types" , "-w" , "-49" ]})
26+ @@ ocaml.text ( / * DESIGN:
2727 - It does not have any code, all its code will be inlined so that
2828 there will never be
2929 {[ require('js')]}
3030 - Its interface should be minimal
31- *)
31+ */
3232
33- (* *
33+ "
3434The Js module mostly contains ReScript bindings to _standard JavaScript APIs_
3535like [console.log](https://developer.mozilla.org/en-US/docs/Web/API/Console/log),
3636or the JavaScript
@@ -57,234 +57,233 @@ In the meantime, there are several options for dealing with the data-last APIs:
5757
5858```rescript
5959/* 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\ " ))
6262
6363/* 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\ " , _))
6666
6767/* 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\ " ))
7070```
7171## Js.Xxx2 Modules
7272
7373Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latters are old modules.
74- * )
74+ " )
7575
76- type 'a t = < .. > as 'a
77- (* * JS object type *)
76+ @ ocaml.doc ( " JS object type " )
77+ type t < 'a > = { .. } as 'a
7878
7979module MapperRt = Js_mapperRt
8080
81- module Internal = struct
82- external opaqueFullApply : 'a - > 'a = " %uncurried_apply"
81+ module Internal = {
82+ external opaqueFullApply : 'a = > 'a = "%uncurried_apply"
8383
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+ }
8888
89- (* */* * )
89+ @@ ocaml.text ( "/*" )
9090
91- (* *
91+ @ ocaml.doc ( "
9292 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
9596
96- type +'a undefined
97- (* *
97+ @ocaml.doc ("
9898 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 >
100101
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
103103
104- (* *
104+ @@ ocaml.text ( "
105105 A value of this type can be undefined, null or 'a. This type is equivalent to Js.Null_undefined.t.
106- * )
106+ " )
107107
108- type +'a null_undefined = 'a nullable
108+ type null_undefined < + 'a > = nullable < 'a >
109109
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"
115115
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"
118118
119- type (+'a, +'e) promise
120- (* *
119+ @ocaml.doc ("
121120 The promise type, defined here for interoperation across packages.
122- *)
121+ " )
122+ type promise <+ 'a , + 'e >
123123
124- external null : 'a null = " #null"
125- (* *
124+ @ocaml.doc ("
126125 The same as empty in `Js.Null`. Compiles to `null`.
127- *)
126+ " )
127+ external null : null <'a > = "#null"
128128
129- external undefined : 'a undefined = " #undefined"
130- (* *
129+ @ocaml.doc ("
131130 The same as empty `Js.Undefined`. Compiles to `undefined`.
132- *)
131+ " )
132+ external undefined : undefined <'a > = "#undefined"
133133
134- external typeof : 'a -> string = " #typeof"
135- (* *
134+ @ocaml.doc ("
136135`typeof x` will be compiled as `typeof x` in JS. Please consider functions in
137136`Js.Types` for a type safe way of reflection.
138- *)
137+ " )
138+ external typeof : 'a => string = "#typeof"
139139
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"
143142
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"
146145
147- external log4 : 'a -> 'b -> 'c -> 'd - > unit = " log" [ @@ val] [ @@ scope "console" ]
146+ @ val @ scope ( "console" ) external log4 : ( 'a , 'b , 'c , 'd ) = > unit = "log"
148147
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"
152153
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"
156157
157- (* * ## Operators * )
158+ @@ ocaml.text ( " ## Operators " )
158159
159- external unsafe_lt : 'a -> 'a -> bool = " #unsafe_lt"
160- (* *
160+ @ocaml.doc ("
161161 `unsafe_lt(a, b)` will be compiled as `a < b`.
162162 It is marked as unsafe, since it is impossible
163163 to give a proper semantics for comparision which applies to any type
164- *)
164+ " )
165+ external unsafe_lt : ('a , 'a ) => bool = "#unsafe_lt"
165166
166- external unsafe_le : 'a -> 'a -> bool = " #unsafe_le"
167- (* *
167+ @ocaml.doc ("
168168 `unsafe_le(a, b)` will be compiled as `a <= b`.
169169 See also `Js.unsafe_lt`.
170- *)
170+ " )
171+ external unsafe_le : ('a , 'a ) => bool = "#unsafe_le"
171172
172- external unsafe_gt : 'a -> 'a -> bool = " #unsafe_gt"
173- (* *
173+ @ocaml.doc ("
174174 `unsafe_gt(a, b)` will be compiled as `a > b`.
175175 See also `Js.unsafe_lt`.
176- *)
176+ " )
177+ external unsafe_gt : ('a , 'a ) => bool = "#unsafe_gt"
177178
178- external unsafe_ge : 'a -> 'a -> bool = " #unsafe_ge"
179- (* *
179+ @ocaml.doc ("
180180 `unsafe_ge(a, b)` will be compiled as `a >= b`.
181181 See also `Js.unsafe_lt`.
182- *)
182+ " )
183+ external unsafe_ge : ('a , 'a ) => bool = "#unsafe_ge"
183184
184- (* * ## Nested Modules * )
185+ @@ ocaml.text ( " ## Nested Modules " )
185186
187+ @ocaml.doc (" Provide utilities for `Js.null<'a>` " )
186188module Null = Js_null
187- (* * Provide utilities for `Js.null<'a>` *)
188189
190+ @ocaml.doc (" Provide utilities for `Js.undefined<'a>` " )
189191module Undefined = Js_undefined
190- (* * Provide utilities for `Js.undefined<'a>` *)
191192
193+ @ocaml.doc (" Provide utilities for `Js.null_undefined` " )
192194module Nullable = Js_null_undefined
193- (* * Provide utilities for `Js.null_undefined` *)
194195
195- module Null_undefined =
196- Js_null_undefined
197- [@ deprecated " Please use `Js.Nullable`" ]
196+ module Null_undefined = Js_null_undefined
198197
198+ @ocaml.doc (" Provide utilities for dealing with Js exceptions " )
199199module Exn = Js_exn
200- (* * Provide utilities for dealing with Js exceptions *)
201200
201+ @ocaml.doc (" Provide bindings to JS array" )
202202module Array = Js_array
203- (* * Provide bindings to JS array*)
204203
204+ @ocaml.doc (" Provide bindings to JS array" )
205205module Array2 = Js_array2
206- (* * Provide bindings to JS array*)
207206
207+ @ocaml.doc (" Provide bindings to JS string " )
208208module String = Js_string
209- (* * Provide bindings to JS string *)
210209
210+ @ocaml.doc (" Provide bindings to JS string " )
211211module String2 = Js_string2
212- (* * Provide bindings to JS string *)
213212
213+ @ocaml.doc (" Provide bindings to JS regex expression " )
214214module Re = Js_re
215- (* * Provide bindings to JS regex expression *)
216215
216+ @ocaml.doc (" Provide bindings to JS Promise " )
217217module Promise = Js_promise
218- (* * Provide bindings to JS Promise *)
219218
219+ @ocaml.doc (" Provide bindings to JS Promise " )
220220module Promise2 = Js_promise2
221- (* * Provide bindings to JS Promise *)
222221
222+ @ocaml.doc (" Provide bindings for JS Date " )
223223module Date = Js_date
224- (* * Provide bindings for JS Date *)
225224
225+ @ocaml.doc (" Provide utilities for JS dictionary object " )
226226module Dict = Js_dict
227- (* * Provide utilities for JS dictionary object *)
228227
228+ @ocaml.doc (" Provide bindings to JS global functions in global namespace" )
229229module Global = Js_global
230- (* * Provide bindings to JS global functions in global namespace*)
231230
231+ @ocaml.doc (" Provide utilities for json " )
232232module Json = Js_json
233- (* * Provide utilities for json *)
234233
234+ @ocaml.doc (" Provide bindings for JS `Math` object " )
235235module Math = Js_math
236- (* * Provide bindings for JS `Math` object *)
237236
237+ @ocaml.doc (" Provide utilities for `Js.t` " )
238238module Obj = Js_obj
239- (* * Provide utilities for `Js.t` *)
240239
240+ @ocaml.doc (" Provide bindings for JS typed array " )
241241module Typed_array = Js_typed_array
242- (* * Provide bindings for JS typed array *)
243242
243+ @ocaml.doc (" Provide bindings for JS typed array " )
244244module TypedArray2 = Js_typed_array2
245- (* * Provide bindings for JS typed array *)
246245
246+ @ocaml.doc (" Provide utilities for manipulating JS types " )
247247module Types = Js_types
248- (* * Provide utilities for manipulating JS types *)
249248
249+ @ocaml.doc (" Provide utilities for JS float " )
250250module Float = Js_float
251- (* * Provide utilities for JS float *)
252251
252+ @ocaml.doc (" Provide utilities for int " )
253253module Int = Js_int
254- (* * Provide utilities for int *)
255254
255+ @ocaml.doc (" Provide utilities for bigint " )
256256module BigInt = Js_bigint
257- (* * Provide utilities for bigint *)
258257
258+ @ocaml.doc (" Provide utilities for File " )
259259module File = Js_file
260- (* * Provide utilities for File *)
261260
261+ @ocaml.doc (" Provide utilities for Blob " )
262262module Blob = Js_blob
263- (* * Provide utilities for Blob *)
264263
264+ @ocaml.doc (" Provide utilities for option " )
265265module Option = Js_option
266- (* * Provide utilities for option *)
267266
267+ @ocaml.doc (" Define the interface for result " )
268268module Result = Js_result
269- (* * Define the interface for result *)
270269
270+ @ocaml.doc (" Provide utilities for list " )
271271module List = Js_list
272- (* * Provide utilities for list *)
273272
273+ @ocaml.doc (" Provides bindings for JS Vector " )
274274module Vector = Js_vector
275- (* * Provides bindings for JS Vector *)
276275
276+ @ocaml.doc (" Provides bindings for console " )
277277module Console = Js_console
278- (* * Provides bindings for console *)
279278
279+ @ocaml.doc (" Provides bindings for ES6 Set " )
280280module Set = Js_set
281- (* * Provides bindings for ES6 Set *)
282281
282+ @ocaml.doc (" Provides bindings for ES6 WeakSet " )
283283module WeakSet = Js_weakset
284- (* * Provides bindings for ES6 WeakSet *)
285284
285+ @ocaml.doc (" Provides bindings for ES6 Map " )
286286module Map = Js_map
287- (* * Provides bindings for ES6 Map *)
288287
288+ @ocaml.doc (" Provides bindings for ES6 WeakMap " )
289289module WeakMap = Js_weakmap
290- (* * Provides bindings for ES6 WeakMap *)
0 commit comments