Javascript binary support of Erlang External Term Format
BSD-3-CLAUSE License
Javascript binary support of Erlang External Term Format (ETF)
git clone https://github.com/saleyn/erlb.js.git
Include erlb.js to your project.
Erl.encode(obj, opts) - Encode a Javascript object into ETF, return ArrayBuffer
suitable for sending via websocket. The object can be a Boolean, Integer, Float,
String, Array, Object (treated as a proplist) or an Atom, Binary,
or Tuple (with the help of Erl.atom(), Erl.binary(), or Erl.tuple(), respectively).
The opts
argument is optional and may contain the following settings:
Value | Values | Default | Description |
---|---|---|---|
mapKeyType | 'atom'/'binary'/'string' | 'binary' | Encode object's map keys using this data type |
Erl.decode(arrayBuffer) - Decode a binary ArrayBuffer into a Javascript object.
Erl.equals(obj1, obj2) - Compare Obj1 and Obj2 for equality.
Erl.toString(obj, opts) - Print a Javascript object in the Erlang notation.
The opts
argument is optional and may contain the following settings:
Value | Values | Default | Description |
---|---|---|---|
compact | true/false | false | Print binaries in compact form (using backticks instead of <<"">> enclosures |
Erl.atom(string) - Create a Javascript object that will be encoded to an Atom.
Erl.binary(uInt8Array) - Create a Javascript object that will be encoded to an Binary.
Erl.tuple(array) - Create a Javascript object that will be encoded to a Tuple.
Erl.pid(node, id, ser, creation) - Create a Javascript object that will be encoded to a Pid.
Erl.ref(node, creation, ids) - Create a Javascript object that will be encoded to a Ref.
The library natively understands the following Javascript types:
You can use provided bin/simple_http_server to serve the content of the current directory to a web browser:
$ bin/simple_http_server 8000
Point your browser to http://localhost:8000/erlb-test.html. The page automatically runs all unit tests defined in the erlb-test.js script.
Serge Aleynikov <saleyn at gmail dot com>
BSD License (see included LICENSE file)