Module Js_of_ocaml__.Js
Dealing with null
and undefined
values.
val null : 'a opt
The
null
value.
val some : 'a -> 'a opt
Consider a value into a possibly null value.
val undefined : 'a optdef
The
undefined
value
val def : 'a -> 'a optdef
Consider a value into a possibly undefined value.
module type OPT = sig ... end
Signatures of a set of standard functions for manipulating optional values.
Types for specifying method and properties of Javascript objects
type +'a t
Type of Javascript objects. The type parameter is used to specify more precisely an object.
type +'a meth
Type used to specify method types: a Javascript object
<m : t1 -> t2 -> ... -> tn -> t Js.meth> Js.t
has a Javascript methodm
expecting n arguments of typest1
totn
and returns a value of typet
.
type +'a gen_prop
Type used to specify the properties of Javascript objects. In practice you should rarely need this type directly, but should rather use the type abbreviations below instead.
type 'a readonly_prop
= < get : 'a; > gen_prop
Type of read-only properties: a Javascript object
<p : t Js.readonly_prop> Js.t
has a read-only propertyp
of typet
.
type 'a writeonly_prop
= < set : 'a -> unit; > gen_prop
Type of write-only properties: a Javascript object
<p : t Js.writeonly_prop> Js.t
has a write-only propertyp
of typet
.
type 'a prop
= < get : 'a; set : 'a -> unit; > gen_prop
Type of read/write properties: a Javascript object
<p : t Js.writeonly_prop> Js.t
has a read/write propertyp
of typet
.
Object constructors
Callbacks to OCaml
type (-'a, +'b) meth_callback
Type of callback functions. A function of type
(u, t1 -> ... -> tn -> t) meth_callback
can be called from Javascript withthis
bound to a value of typeu
and up to n arguments of typest1
totn
. The system takes care of currification, so less than n arguments can be provided. As a special case, a callback of type(t, unit -> t) meth_callback
can be called from Javascript with no argument. It will behave as if it was called with a single argument of typeunit
.
type 'a callback
= (unit, 'a) meth_callback
Type of callback functions intended to be called without a meaningful
this
implicit parameter.
val wrap_callback : ('a -> 'b) -> ('c, 'a -> 'b) meth_callback
Wrap an OCaml function so that it can be invoked from Javascript.
val wrap_meth_callback : ('b -> 'a) -> ('b, 'a) meth_callback
Wrap an OCaml function so that it can be invoked from Javascript. The first parameter of the function will be bound to the value of the
this
implicit parameter.
Javascript standard objects
val _true : bool t
Javascript
true
boolean.
val _false : bool t
Javascript
false
boolean.
type match_result_handle
A handle to a match result. Use function
Js.match_result
to get the correspondingMatchResult
object. (This type is used to resolved the mutual dependency between string and array type definitions.)
type string_array
Opaque type for string arrays. You can get the actual
Array
object using functionJs.str_array
. (This type is used to resolved the mutual dependency between string and array type definitions.)
class type js_string = object ... end
Specification of Javascript string objects.
and regExp = object ... end
Specification of Javascript regular expression objects.
class type string_constr = object ... end
Specification of the string constructor, considered as an object.
val string_constr : string_constr t
The string constructor, as an object.
val regExp : (js_string t -> regExp t) constr
Constructor of
RegExp
objects. The expressionjsnew regExp (s)
builds the regular expression specified by strings
.
val regExp_withFlags : (js_string t -> js_string t -> regExp t) constr
Constructor of
RegExp
objects. The expressionjsnew regExp (s, f)
builds the regular expression specified by strings
using flagsf
.
val regExp_copy : (regExp t -> regExp t) constr
Constructor of
RegExp
objects. The expressionjsnew regExp (r)
builds a copy of regular expressionr
.
class type 'a js_array = object ... end
Specification of Javascript regular arrays. Use
Js.array_get
andJs.array_set
to access and set array elements.
val object_keys : 'a t -> js_string t js_array t
Returns jsarray containing keys of the object as Object.keys does.
val array_empty : 'a js_array t constr
Constructor of
Array
objects. The expressionjsnew array_empty ()
returns an empty array.
val array_length : (int -> 'a js_array t) constr
Constructor of
Array
objects. The expressionjsnew array_length (l)
returns an array of lengthl
.
val array_get : 'a js_array t -> int -> 'a optdef
Array access:
array_get a i
returns the element at indexi
of arraya
. Returnsundefined
if there is no element at this index.
val array_set : 'a js_array t -> int -> 'a -> unit
Array update:
array_set a i v
putsv
at indexi
in arraya
.
val array_map : ('a -> 'b) -> 'a js_array t -> 'b js_array t
Array map:
array_map f a
isa##map(wrap_callback (fun elt idx arr -> f elt))
.
val array_mapi : (int -> 'a -> 'b) -> 'a js_array t -> 'b js_array t
Array mapi:
array_mapi f a
isa##map(wrap_callback (fun elt idx arr -> f idx elt))
.
class type match_result = object ... end
Specification of match result objects
val str_array : string_array t -> js_string t js_array t
Convert an opaque
string_array t
object into an array of string. (Used to resolved the mutual dependency between string and array type definitions.)
val match_result : match_result_handle t -> match_result t
Convert a match result handle into a
MatchResult
object. (Used to resolved the mutual dependency between string and array type definitions.)
class type number = object ... end
Specification of Javascript number objects.
class type date = object ... end
Specification of Javascript date objects.
val date_now : date t constr
Constructor of
Date
objects:jsnew date_now ()
returns aDate
object initialized with the current date.
val date_fromTimeValue : (float -> date t) constr
Constructor of
Date
objects:jsnew date_fromTimeValue (t)
returns aDate
object initialized with the time valuet
.
val date_month : (int -> int -> date t) constr
Constructor of
Date
objects:jsnew date_fromTimeValue (y, m)
returns aDate
object corresponding to yeary
and monthm
.
val date_day : (int -> int -> int -> date t) constr
Constructor of
Date
objects:jsnew date_fromTimeValue (y, m, d)
returns aDate
object corresponding to yeary
, monthm
and dayd
.
val date_hour : (int -> int -> int -> int -> date t) constr
Constructor of
Date
objects:jsnew date_fromTimeValue (y, m, d, h)
returns aDate
object corresponding to yeary
to hourh
.
val date_min : (int -> int -> int -> int -> int -> date t) constr
Constructor of
Date
objects:jsnew date_fromTimeValue (y, m, d, h, m')
returns aDate
object corresponding to yeary
to minutem'
.
val date_sec : (int -> int -> int -> int -> int -> int -> date t) constr
Constructor of
Date
objects:jsnew date_fromTimeValue (y, m, d, h, m', s)
returns aDate
object corresponding to yeary
to seconds
.
val date_ms : (int -> int -> int -> int -> int -> int -> int -> date t) constr
Constructor of
Date
objects:jsnew date_fromTimeValue (y, m, d, h, m', s, ms)
returns aDate
object corresponding to yeary
to millisecondms
.
class type date_constr = object ... end
Specification of the date constructor, considered as an object.
val date : date_constr t
The date constructor, as an object.
class type math = object ... end
Specification of Javascript math object.
class type error = object ... end
Specification of Javascript error object.
val error_constr : (js_string t -> error t) constr
Constructor of
Error
objects:jsnew error_constr (msg)
returns anError
object with the messagemsg
.
exception
Error of error t
The
Error
exception wrap javascript exceptions when caught by OCaml code. In case the javascript exception is not an instance of javascriptError
, it will be serialized and wrapped into aFailure
exception.
class type json = object ... end
Specification of Javascript JSON object.
Standard Javascript functions
val decodeURI : js_string t -> js_string t
Decode a URI: replace by the corresponding byte all escape sequences but the ones corresponding to a URI reserved character and convert the string from UTF-8 to UTF-16.
val decodeURIComponent : js_string t -> js_string t
Decode a URIComponent: replace all escape sequences by the corresponding byte and convert the string from UTF-8 to UTF-16.
val encodeURI : js_string t -> js_string t
Encode a URI: convert the string to UTF-8 and replace all unsafe bytes by the corresponding escape sequence.
val encodeURIComponent : js_string t -> js_string t
Same as
encodeURI
, but also encode URI reserved characters.
val escape : js_string t -> js_string t
Escape a string: unsafe UTF-16 code points are replaced by 2-digit and 4-digit escape sequences.
Conversion functions between Javascript and OCaml types
val bool : bool -> bool t
Conversion of booleans from OCaml to Javascript.
val to_bool : bool t -> bool
Conversion of booleans from Javascript to OCaml.
val string : string -> js_string t
Conversion of strings from OCaml to Javascript. (The OCaml string is considered to be encoded in UTF-8 and is converted to UTF-16.)
Convenience coercion functions
val coerce : 'a -> ('a -> 'b Opt.t) -> ('a -> 'b) -> 'b
Apply a possibly failing coercion function.
coerce v c f
attempts to apply coercionc
to valuev
. If the coercion returnsnull
, functionf
is called.
val coerce_opt : 'a Opt.t -> ('a -> 'b Opt.t) -> ('a -> 'b) -> 'b
Apply a possibly failing coercion function.
coerce_opt v c f
attempts to apply coercionc
to valuev
. Ifv
isnull
or the coercion returnsnull
, functionf
is called. Typical usage is the following:Js.coerce_opt (Dom_html.document##getElementById id) Dom_html.CoerceTo.div (fun _ -> assert false)
Type checking operators.
Debugging operations.
Export functionality.
Export values to module.exports
if it exists or to the global object otherwise.
val export_all : 'a t -> unit
export_all obj
export every key ofobj
object.export_all object%js method add x y = x +. y method abs x = abs_float x val zero = 0. end
Unsafe operations.
module Unsafe : sig ... end
Unsafe Javascript operations
Deprecated functions and types.
type float_prop
= float prop
Type of float properties.