Skip to content

devinus/execjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

79273c0 · Aug 13, 2018

History

51 Commits
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Nov 1, 2013
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018
Aug 13, 2018

Repository files navigation

Execjs

Build Status Hex.pm Version Hex.pm Download Total

Execjs allows you easily run JavaScript from Elixir. It can automatically pick the best runtime available on the system.

Runtimes

Execjs supports the following runtimes:

Use the application environment (application key: :execjs, key: :runtime) to set the runtime Execjs uses. Alternatively, the EXECJS_RUNTIME environment variable can also be used to set the runtime.

Usage

eval

iex> "'red yellow blue'.split(' ')" |> Execjs.eval
["red", "yellow", "blue"]

compile/call

iex> {source, 0} = System.cmd("curl", ["-fsSL", "--compressed", "https://coffeescript.org/browser-compiler/coffeescript.js"])
iex> context = Execjs.compile(source)
iex> Execjs.call(context, "CoffeeScript.compile", ["square = (x) -> x * x"])
"(function() {\n  var square;\n\n  square = function(x) {\n    return x * x;\n  };\n\n}).call(this);\n"