package quickjs
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=594fac60b9273af7e1903f0689efa353121309d8de911376f91966c32cd3ab7f
sha512=68beb126919a214fa9e46d84566c97e6ff3667c6c4478f352f1145e5bf1888b2a5eaca9855f39d734b2e9dc5bc0c7650f45679d177d546a2b0ba53dced5f2d1f
Description
Published: 11 Jan 2026
README
quickjs
quickjs.ml is a set of OCaml bindings to some libraries from QuickJS, a small and embeddable JavaScript engine that aims to support the latest ECMAScript specification.
This project exposes two libraries:
quickjs.c: Low-level OCaml bindings to QuickJS C libs (libregexp,libunicode,js_dtoa,js_atod, andcutils)quickjs: A high-level API that mirrors JavaScript's built-in objects and methods. Modules includeRegExp,String,Number, andGlobal.
Motivation
OCaml can target both native code and JavaScript (via Melange), enabling "universal" code that runs on both platforms. However, JavaScript's specific behavior (such as Unicode, number formatting, and regular expressions) often differs between native OCaml and browser engines. Rather than reimplementing these complex behaviors from scratch, we leverage QuickJS.
This project bridges that gap by bringing the same behavior as JavaScript engines (SpiderMonkey, JavaScriptCore, ChakraCore, v8) into native OCaml. With quickjs.ml, universal code produces identical results whether it runs natively or in the browser.
TC39/test262 Compatibility
We are translating TC39/test262 tests into OCaml to ensure full compatibility with the ECMAScript specification.
Documentation
Usage
Add quickjs library in dune
(libraries quickjs)open Quickjs
(* RegExp - JavaScript-compatible regular expressions *)
let re = RegExp.compile ~flags:"g" "(?<word>\\w+)" |> Result.get_ok in
let result = RegExp.exec re "hello world" in
RegExp.captures result (* [| "hello"; "hello" |] *)
RegExp.group "word" result (* Some "hello" *)
RegExp.exec re "hello world" (* next match: "world" *)
(* Number.Prototype - JavaScript-identical number formatting *)
Number.Prototype.to_string 0.1 (* "0.1" - no floating point artifacts *)
Number.Prototype.to_fixed 2 3.14159 (* "3.14" *)
Number.Prototype.to_radix 16 255.0 (* "ff" *)
Number.Prototype.to_exponential 2 123.456 (* "1.23e+2" *)
(* Global - JavaScript global functions *)
Global.parse_float "3.14" (* Some 3.14 *)
Global.parse_float ~options:Global.js_parse_options "0xff" (* Some 255.0 *)
(* Number - fast integer to string *)
Number.of_int 42 (* "42" *)
Number.of_int_radix ~radix:16 255 (* "ff" *)
Number.of_int64 9223372036854775807L (* "9223372036854775807" *)
(* String.Prototype - JavaScript string methods *)
String.Prototype.to_lower_case "HELLO" (* "hello" *)
String.Prototype.to_upper_case "world" (* "WORLD" *)For more details, see the API reference.
Dev Dependencies (4)
-
ocamlformat
with-dev-setup -
ocaml-lsp-server
with-dev-setup -
odoc
with-doc -
alcotest
with-test
Used by (2)
-
server-reason-react
>= "0.4.1" - universal-portal