package brr
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=45cdf73c6a23c8fc4609a32ae2196d4790e5bdba34ca0b784bff9c0b70dab233eb336f1c11dc3002451042ff4cf25b643098ad0d011f14c3d6175842113bed21
doc/brr/Jv/index.html
Module JvSource
JavaScript values.
See the FFI manual and cookbook for a gentle introduction.
Values
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.
instanceof o c is true if o is an instance of constructor c.
Null and undefined
is_null v is true iff v is strictly equal to null.
is_undefined v is true iff v is strictly equal to undefined.
of_option ~none conv o is none if o is None and conv v if o is Some v.
Objects
global refers to the global object.
Properties
The type for US-ASCII JavaScript object property names.
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.
Creating
Methods
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.
Booleans
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.
Integers
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.
of_int i is the int value i as a JavaScript Number value. The conversion is lossess.
Floating points
to_float v is the JavaScript Number value v as a float value. The conversion is lossless.
of_float f is the float value f as a JavaScript Number value. The conversion is lossless.
32-bits integers
to_int32 v is the JavaScript Number value v as an int32 value. The conversion is lossless provided v is a 32-bit signed integer.
of_int32 f is the int32 value f as a JavaScript Number value. The conversion is lossless.
JavaScript strings
OCaml strings
of_string v is a JavaScript string from the UTF-8 encoded OCaml string v. Shortcut for of_jstr (Jstr.v v).
to_string v is an UTF-8 encoded OCaml string from the JavaScript string v. Shortcut for Jstr.to_string (to_jstr v).
Arrays
is_array v determines if v is a JavaScript array using the Array.isArray function.
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.
Specialized conversions
Can be faster.
of_jv_array a is a as a JavaScript array of JavaScript values.
JavaScript array manipulation
Functions
callback ~arity f makes function f with arity arity callable from JavaScript.
Errors and exceptions
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.
Iterator protocol
Promises
JavaScript Unicode identifiers
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.
delete' o p deletes property p of o. The property p or o becomes undefined.
find_map' f p o is Option.map f (find' p o).
call' o m args calls method m on o with arguments m. m must be a JavaScript string.
Entering the debugger
debugger () stops and enters the JavaScript debugger (if available).
Feature detection
has p v tests whether Jv.repr v has a member or method p
defined v is Jv.is_some (J.repr v). Tests whether v is neither null nor undefined.