Swiftpack.co - Package - kateinoigakukun/JavaScriptKit

JavaScriptKit

Run unit tests

Swift framework to interact with JavaScript through WebAssembly.

Requirements

This library only supports swiftwasm/swift distribution toolchain. Please install Swift for WebAssembly toolchain from Release Page

The toolchains can be installed via swiftenv like official nightly toolchain.

e.g.


$ swiftenv install https://github.com/swiftwasm/swift/releases/download/swift-wasm-DEVELOPMENT-SNAPSHOT-2020-03-08-a/swift-wasm-DEVELOPMENT-SNAPSHOT-2020-03-08-a-osx.tar.gz
$ swift --version
Swift version 5.2-dev (LLVM 7fc8796bc1, Swift 5be35e7aee)
Target: x86_64-apple-darwin19.3.0

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

Github

link
Stars: 19

Dependencies

Used By

Total: 0

Releases

- 2020-03-09 04:07:01