|
| 1 | +(* Copyright (C) 2015-2016 Bloomberg Finance L.P. |
| 2 | + * |
| 3 | + * This program is free software: you can redistribute it and/or modify |
| 4 | + * it under the terms of the GNU Lesser General Public License as published by |
| 5 | + * the Free Software Foundation, either version 3 of the License, or |
| 6 | + * (at your option) any later version. |
| 7 | + * |
| 8 | + * In addition to the permissions granted to you by the LGPL, you may combine |
| 9 | + * or link a "work that uses the Library" with a publicly distributed version |
| 10 | + * of this file to produce a combined library or application, then distribute |
| 11 | + * that combined work under the terms of your choosing, with no requirement |
| 12 | + * to comply with the obligations normally placed on you by section 4 of the |
| 13 | + * LGPL version 3 (or the corresponding section of a later version of the LGPL |
| 14 | + * should you choose to use a later version). |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Lesser General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Lesser General Public License |
| 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. *) |
| 24 | + |
| 25 | +[@@@bs.config {flags = [|"-unboxed-types";"-w" ;"-49"|]}] |
| 26 | +(* DESIGN: |
| 27 | + - It does not have any code, all its code will be inlined so that |
| 28 | + there will never be |
| 29 | + {[ require('js')]} |
| 30 | + - Its interface should be minimal |
| 31 | +*) |
| 32 | + |
| 33 | +(** This library provides bindings and necessary support for JS FFI. |
| 34 | + It contains all bindings into [Js] namespace. |
| 35 | +
|
| 36 | + @example {[ |
| 37 | + [| 1;2;3;4|] |
| 38 | + |. Js.Array2.map (fun x -> x + 1 ) |
| 39 | + |. Js.Array2.reduce (+) 0 |
| 40 | + |. Js.log |
| 41 | + ]} |
| 42 | +*) |
| 43 | + |
| 44 | +(**/**) |
| 45 | +(** Types for JS objects *) |
| 46 | +type 'a t = < .. > as 'a |
| 47 | +(**/**) |
| 48 | + |
| 49 | +(* internal types for FFI, these types are not used by normal users |
| 50 | + Absent cmi file when looking up module alias. |
| 51 | +*) |
| 52 | +module Fn = struct |
| 53 | + type 'a arity0 = { |
| 54 | + i0 : unit -> 'a [@internal] |
| 55 | + } |
| 56 | + type 'a arity1 = { |
| 57 | + i1 : 'a [@internal] |
| 58 | + } |
| 59 | + type 'a arity2 = { |
| 60 | + i2 : 'a [@internal] |
| 61 | + } |
| 62 | + type 'a arity3 = { |
| 63 | + i3 : 'a [@internal] |
| 64 | + } |
| 65 | + type 'a arity4 = { |
| 66 | + i4 : 'a [@internal] |
| 67 | + } |
| 68 | + type 'a arity5 = { |
| 69 | + i5 : 'a [@internal] |
| 70 | + } |
| 71 | + type 'a arity6 = { |
| 72 | + i6 : 'a [@internal] |
| 73 | + } |
| 74 | + type 'a arity7 = { |
| 75 | + i7 : 'a [@internal] |
| 76 | + } |
| 77 | + type 'a arity8 = { |
| 78 | + i8 : 'a [@internal] |
| 79 | + } |
| 80 | + type 'a arity9 = { |
| 81 | + i9 : 'a [@internal] |
| 82 | + } |
| 83 | + type 'a arity10 = { |
| 84 | + i10 : 'a [@internal] |
| 85 | + } |
| 86 | + type 'a arity11 = { |
| 87 | + i11 : 'a [@internal] |
| 88 | + } |
| 89 | + type 'a arity12 = { |
| 90 | + i12 : 'a [@internal] |
| 91 | + } |
| 92 | + type 'a arity13 = { |
| 93 | + i13 : 'a [@internal] |
| 94 | + } |
| 95 | + type 'a arity14 = { |
| 96 | + i14 : 'a [@internal] |
| 97 | + } |
| 98 | + type 'a arity15 = { |
| 99 | + i15 : 'a [@internal] |
| 100 | + } |
| 101 | + type 'a arity16 = { |
| 102 | + i16 : 'a [@internal] |
| 103 | + } |
| 104 | + type 'a arity17 = { |
| 105 | + i17 : 'a [@internal] |
| 106 | + } |
| 107 | + type 'a arity18 = { |
| 108 | + i18 : 'a [@internal] |
| 109 | + } |
| 110 | + type 'a arity19 = { |
| 111 | + i19 : 'a [@internal] |
| 112 | + } |
| 113 | + type 'a arity20 = { |
| 114 | + i20 : 'a [@internal] |
| 115 | + } |
| 116 | + type 'a arity21 = { |
| 117 | + i21 : 'a [@internal] |
| 118 | + } |
| 119 | + type 'a arity22 = { |
| 120 | + i22 : 'a [@internal] |
| 121 | + } |
| 122 | +end |
| 123 | + |
| 124 | +(**/**) |
| 125 | +module MapperRt = Js_mapperRt |
| 126 | +module Internal = struct |
| 127 | + open Fn |
| 128 | + external opaqueFullApply : 'a -> 'a = "%uncurried_apply" |
| 129 | + |
| 130 | + (* Use opaque instead of [._n] to prevent some optimizations happening *) |
| 131 | + external run : 'a arity0 -> 'a = "#run" |
| 132 | + external opaque : 'a -> 'a = "%opaque" |
| 133 | + |
| 134 | +end |
| 135 | +(**/**) |
| 136 | + |
| 137 | + |
| 138 | +type + 'a null |
| 139 | +(** nullable, value of this type can be either [null] or ['a] |
| 140 | + this type is the same as type [t] in {!Null} |
| 141 | +*) |
| 142 | + |
| 143 | +type + 'a undefined |
| 144 | +(** value of this type can be either [undefined] or ['a] |
| 145 | + this type is the same as type [t] in {!Undefined} *) |
| 146 | + |
| 147 | +type + 'a nullable |
| 148 | +(** value of this type can be [undefined], [null] or ['a] |
| 149 | + this type is the same as type [t] n {!Null_undefined} *) |
| 150 | + |
| 151 | +type + 'a null_undefined = 'a nullable |
| 152 | + |
| 153 | +external toOption : 'a nullable -> 'a option = "#nullable_to_opt" |
| 154 | +external undefinedToOption : 'a undefined -> 'a option = "#undefined_to_opt" |
| 155 | +external nullToOption : 'a null -> 'a option = "#null_to_opt" |
| 156 | + |
| 157 | +external isNullable : 'a nullable -> bool = "#is_nullable" |
| 158 | + |
| 159 | +(** The same as {!test} except that it is more permissive on the types of input *) |
| 160 | +external testAny : 'a -> bool = "#is_nullable" |
| 161 | + |
| 162 | + |
| 163 | +type (+'a, +'e) promise |
| 164 | +(** The promise type, defined here for interoperation across packages |
| 165 | + @deprecated please use {!Js.Promise} |
| 166 | +*) |
| 167 | + |
| 168 | +external null : 'a null = "#null" |
| 169 | +(** The same as [empty] in {!Js.Null} will be compiled as [null]*) |
| 170 | + |
| 171 | +external undefined : 'a undefined = "#undefined" |
| 172 | +(** The same as [empty] {!Js.Undefined} will be compiled as [undefined]*) |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | +external typeof : 'a -> string = "#typeof" |
| 177 | +(** [typeof x] will be compiled as [typeof x] in JS |
| 178 | + Please consider functions in {!Types} for a type safe way of reflection |
| 179 | +*) |
| 180 | + |
| 181 | +external log : 'a -> unit = "log" |
| 182 | +[@@val] [@@scope "console"] |
| 183 | +(** A convenience function to log everything *) |
| 184 | + |
| 185 | +external log2 : 'a -> 'b -> unit = "log" |
| 186 | +[@@bs.val] [@@bs.scope "console"] |
| 187 | +external log3 : 'a -> 'b -> 'c -> unit = "log" |
| 188 | +[@@bs.val] [@@bs.scope "console"] |
| 189 | +external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log" |
| 190 | +[@@bs.val] [@@bs.scope "console"] |
| 191 | + |
| 192 | +external logMany : 'a array -> unit = "log" |
| 193 | +[@@bs.val] [@@bs.scope "console"] [@@bs.splice] |
| 194 | +(** A convenience function to log more than 4 arguments *) |
| 195 | + |
| 196 | +external eqNull : 'a -> 'a null -> bool = "%bs_equal_null" |
| 197 | +external eqUndefined : 'a -> 'a undefined -> bool = "%bs_equal_undefined" |
| 198 | +external eqNullable : 'a -> 'a nullable -> bool = "%bs_equal_nullable" |
| 199 | + |
| 200 | +(** {4 operators }*) |
| 201 | + |
| 202 | +external unsafe_lt : 'a -> 'a -> bool = "#unsafe_lt" |
| 203 | +(** [unsafe_lt a b] will be compiled as [a < b]. |
| 204 | + It is marked as unsafe, since it is impossible |
| 205 | + to give a proper semantics for comparision which applies to any type |
| 206 | +*) |
| 207 | + |
| 208 | + |
| 209 | +external unsafe_le : 'a -> 'a -> bool = "#unsafe_le" |
| 210 | +(** [unsafe_le a b] will be compiled as [a <= b]. |
| 211 | + See also {!unsafe_lt} |
| 212 | +*) |
| 213 | + |
| 214 | + |
| 215 | +external unsafe_gt : 'a -> 'a -> bool = "#unsafe_gt" |
| 216 | +(** [unsafe_gt a b] will be compiled as [a > b]. |
| 217 | + See also {!unsafe_lt} |
| 218 | +*) |
| 219 | + |
| 220 | +external unsafe_ge : 'a -> 'a -> bool = "#unsafe_ge" |
| 221 | +(** [unsafe_ge a b] will be compiled as [a >= b]. |
| 222 | + See also {!unsafe_lt} |
| 223 | +*) |
| 224 | + |
| 225 | + |
| 226 | +(** {12 nested modules}*) |
| 227 | + |
| 228 | +module Null = Js_null |
| 229 | +(** Provide utilities around ['a null] *) |
| 230 | + |
| 231 | +module Undefined = Js_undefined |
| 232 | +(** Provide utilities around {!undefined} *) |
| 233 | + |
| 234 | +module Nullable = Js_null_undefined |
| 235 | +(** Provide utilities around {!null_undefined} *) |
| 236 | + |
| 237 | +module Null_undefined = Js_null_undefined |
| 238 | +(** @deprecated please use {!Js.Nullable} *) |
| 239 | + |
| 240 | +module Exn = Js_exn |
| 241 | +(** Provide utilities for dealing with Js exceptions *) |
| 242 | + |
| 243 | +module Array = Js_array |
| 244 | +(** Provide bindings to Js array*) |
| 245 | + |
| 246 | +module Array2 = Js_array2 |
| 247 | +(** Provide bindings to Js array*) |
| 248 | + |
| 249 | +module String = Js_string |
| 250 | +(** Provide bindings to JS string *) |
| 251 | + |
| 252 | +module String2 = Js_string2 |
| 253 | +(** Provide bindings to JS string *) |
| 254 | + |
| 255 | +module Re = Js_re |
| 256 | +(** Provide bindings to Js regex expression *) |
| 257 | + |
| 258 | +module Promise = Js_promise |
| 259 | +(** Provide bindings to JS promise *) |
| 260 | + |
| 261 | +module Date = Js_date |
| 262 | +(** Provide bindings for JS Date *) |
| 263 | + |
| 264 | +module Dict = Js_dict |
| 265 | +(** Provide utilities for JS dictionary object *) |
| 266 | + |
| 267 | +module Global = Js_global |
| 268 | +(** Provide bindings to JS global functions in global namespace*) |
| 269 | + |
| 270 | +module Json = Js_json |
| 271 | +(** Provide utilities for json *) |
| 272 | + |
| 273 | +module Math = Js_math |
| 274 | +(** Provide bindings for JS [Math] object *) |
| 275 | + |
| 276 | +module Obj = Js_obj |
| 277 | +(** Provide utilities for {!Js.t} *) |
| 278 | + |
| 279 | +module Typed_array = Js_typed_array |
| 280 | +(** Provide bindings for JS typed array *) |
| 281 | + |
| 282 | +module TypedArray2 = Js_typed_array2 |
| 283 | +(** Provide bindings for JS typed array *) |
| 284 | + |
| 285 | +module Types = Js_types |
| 286 | +(** Provide utilities for manipulating JS types *) |
| 287 | + |
| 288 | +module Float = Js_float |
| 289 | +(** Provide utilities for JS float *) |
| 290 | + |
| 291 | +module Int = Js_int |
| 292 | +(** Provide utilities for int *) |
| 293 | + |
| 294 | +module Option = Js_option |
| 295 | +(** Provide utilities for option *) |
| 296 | + |
| 297 | +module Result = Js_result |
| 298 | +(** Define the interface for result *) |
| 299 | + |
| 300 | +module List = Js_list |
| 301 | +(** Provide utilities for list *) |
| 302 | + |
| 303 | +module Vector = Js_vector |
| 304 | + |
| 305 | +module Console = Js_console |
0 commit comments