Js

This library provides bindings and necessary support for JS FFI. It contains all bindings into Js namespace.

RE
[|1, 2, 3, 4|] ->Js.Array2.map(x => x + 1) ->Js.Array2.reduce((+), 0) ->Js.log;
type t(+'a);

Js object type.

let x: { . "x": int, "y": int, } = [%obj {x: 1, y: 2}];
type null(+'a);

nullable, value of this type can be either null or 'a this type is the same as type t in Js.Null

type undefined(+'a);

value of this type can be either undefined or 'a this type is the same as type t in Js.Undefined

type nullable(+'a);

value of this type can be undefined, null or 'a this type is the same as type t n Js.Null_undefined

type null_undefined('a) = Js.nullable('a);
let toOption: Js.nullable('a) => option('a);
let undefinedToOption: Js.undefined('a) => option('a);
let nullToOption: Js.null('a) => option('a);
let test: Js.nullable('a) => bool;
let isNullable: Js.nullable('a) => bool;
let testAny: 'a => bool;

The same as Js.test except that it is more permissive on the types of input.

type promise(+'a, +'e);

Deprecated. please use Js.Promise. The promise type, defined here for interoperation across packages.

let null: Js.null('a);

The same as empty in Js.Null. Will be compiled as null.

let undefined: Js.undefined('a);

The same as empty Js.Undefined. Will be compiled as undefined.

let typeof: 'a => string;

typeof x will be compiled as typeof x in JS. Please consider functions in Js.Types for a type safe way of reflection.

let log: 'a => unit; let log2: ('a, 'b) => unit; let log3: ('a, 'b, 'c) => unit; let log4: ('a, 'b, 'c, 'd) => unit;

A convenience function to log everything.

let logMany: array('a) => unit;

A convenience function to log more than 4 arguments

let eqNull: ('a, null('a)) => bool; let eqUndefined: ('a, undefined('a)) => bool; let eqNullable: ('a, nullable('a)) => bool;
let unsafe_lt: ('a, 'a) => bool;

unsafe_lt a b will be compiled as a < b. It is marked as unsafe, since it is impossible to give a proper semantics for comparision which applies to any type.

let unsafe_le: ('a, 'a) => bool;

unsafe_le a b will be compiled as a <= b. See also Js.unsafe_lt.

let unsafe_gt: ('a, 'a) => bool;

unsafe_gt a b will be compiled as a > b. See also Js.unsafe_lt.

let unsafe_ge: ('a, 'a) => bool;

unsafe_ge a b will be compiled as a >= b. See also Js.unsafe_lt.