Skip to content

swiftwasm/JavaScriptKit

Repository files navigation

JavaScriptKit

Run unit tests

Swift framework to interact with JavaScript through WebAssembly.

Usage

This JavaScript code

const alert = window.alert
const document = window.document

const divElement = document.createElement("div")
divElement.innerText = "Hello, world"
const body = document.body
body.appendChild(divElement)

alert("JavaScript is running on browser!")

Can be written in Swift using JavaScriptKit

import JavaScriptKit

let alert = JSObjectRef.global.alert.function!
let document = JSObjectRef.global.document.object!

let divElement = document.createElement!("div").object!
divElement.innerText = "Hello, world"
let body = document.body.object!
_ = body.appendChild!(divElement)

alert("Swift is running on browser!")

Please see Example directory for more information