Getting Started
Installation
using Pkg
Pkg.add(url="https://github.com/GroupTherapyOrg/JavaScriptTarget.jl")Basic Usage
Write a Julia function with typed arguments, then transpile to JavaScript:
using JavaScriptTarget
function add(a::Int32, b::Int32)::Int32
return a + b
end
result = compile(add, (Int32, Int32))
println(result.js)
# Output: function add(a, b) { return (a + b) | 0; }Type Mappings
Julia types map naturally to JavaScript. This table shows the core type mappings — see the full API reference for comprehensive coverage of 80+ supported operations across math, strings, arrays, broadcasting, structs, and more.
| Julia | JavaScript |
|---|---|
| Int32, Int64 | number | 0 |
| Float64 | number |
| String | string |
| Bool | boolean |
| Vector{T} | Array |
| Matrix{T} (ND arrays) | Nested Array: [[row1], [row2]] |
| Dict{K,V} | Map |
| Set{T} | Set |
| struct | ES6 class |
| Tuple | Array |
| Nothing | null |
With Therapy.jl
JST powers Therapy.jl's @island components. Write Julia → JST transpiles to inline JS → browser hydrates.
using Therapy
@island function Counter(; initial::Int = 0)
count, set_count = create_signal(initial)
return Div(
Button(:on_click => () -> set_count(count() + 1), "+"),
Span(count)
)
end
# → Transpiles to ~500 bytes of inline JavaScript