Library
Module
Module type
Parameter
Class
Class type
JavaScript values.
See the FFI manual and cookbook for a gentle introduction.
The type for JavaScript values. A value of this type represents a value of any JavaScript primitive type.
equal v0 v1
is JavaScript ==
equality.
strict_equal v0 v1
is JavaScript's strict equality. OCaml's (==)
is mapped on that equality.
val repr : 'a -> t
repr v
is the OCaml value v
as its JavaScript value representation.
val is_null : t -> bool
is_null v
is true
iff v
is strictly equal to null
.
val is_undefined : t -> bool
is_undefined v
is true
iff v
is strictly equal to undefined
.
val is_none : t -> bool
is_none v
is is_null v || is_undefined v
.
val is_some : t -> bool
is_some v
is not (is_none v)
.
of_option ~none conv o
is none
if o
is None
and conv v
if o
is Some v
.
val global : t
global
refers to the global object.
delete o p
deletes property p
of o
. The property p
or o
becomes undefined
.
set_if_some o p v
sets property p
of o
if v
is Some p
. Otherwise the p
is left untouched in o
.
new_obj c args
creates an object with constructor function c
and arguments args
. Lookup contructor functions in the Jv.global
object.
call o m args
calls the method named m
on o
with arguments m
. m
is assumed to be made of US-ASCII characters only, use call'
if that is not the case.
val true' : t
true
is JavaScript true
.
val false' : t
false'
is JavaScript false
.
val to_bool : t -> bool
to_bool v
is the JavaScript Boolean
value v
as a bool
value. This is unsafe, only use if v
is guaranted to be a JavaScript boolean.
val of_bool : bool -> t
of_bool b
is the bool
value b
as a JavaScript Boolean
value.
module Bool : sig ... end
bool
properties accessors.
val to_int : t -> int
to_int v
is the JavaScript Number
value v
as an int
value. The conversion is lossless provided v
is integral. This is unsafe, only use if v
is guaranteed to be a JavaScript number.
val of_int : int -> t
of_int i
is the int
value i
as a JavaScript Number
value. The conversion is lossess.
module Int : sig ... end
int
properties accessors.
val to_float : t -> float
to_float v
is the JavaScript Number
value v
as a float
value. The conversion is lossless.
val of_float : float -> t
of_float f
is the float
value f
as a JavaScript Number
value. The conversion is lossless.
module Float : sig ... end
float
object properties.
module Jstr : sig ... end
Jstr
object properties.
val of_string : string -> t
of_string v
is a JavaScript string from the UTF-8 encoded OCaml string v
. Shortcut for of_jstr (Jstr.v v)
.
val to_string : t -> string
to_string v
is an UTF-8 encoded OCaml string from the JavaScript string v
. Shortcut for Jstr.to_string (to_jstr v)
.
to_array conv a
is an array
value made of the JavaScript array a
whose elements are converted with conv
.
of_array conv a
is a JavaScript Array
value made of the array
value a
whose element are converted to JavaScript values with conv
.
to_list conv a
is a list
value made of the JavaScript array a
whose elements are converted with conv
.
of_list conv l
is the JavaScript Array
value made of the list
value l
whose element are converted to JavaScript values with conv
.
Can be faster.
module Jarray : sig ... end
JavaScript arrays.
apply f args
calls function f
with arguments args
. Lookup functions names in the Jv.global
object.
val callback : arity:int -> (_ -> _) -> t
callback ~arity f
makes function f
with arity arity
callable from JavaScript.
module Error : sig ... end
Error objects.
exception Error of Error.t
This OCaml exception represents any exception thrown by JavaScript code that is an instance of the Error exception. You should match on this exception in OCaml code to catch JavaScript exceptions.
throw ?name msg
throws a JavaScript exception with error object Jv.Error.v
?name msg
.
module It : sig ... end
JavaScript iterator protocol.
module Promise : sig ... end
JavaScript promise support.
The functions above only work with US-ASCII OCaml string literals. If you hit general Unicode identifiers create JavaScript strings representing them with Jstr.v
and use the following functions.
type prop' = Jstr.t
The type for full Unicode JavaScript object property names.
delete' o p
deletes property p
of o
. The property p
or o
becomes undefined
.
call' o m args
calls method m
on o
with arguments m
. m
must be a JavaScript string.
defined v
is Jv.is_some (J.repr v)
. Tests whether v
is neither null nor undefined.
module type CONV = sig ... end
Abstract type conversion iterface.