Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

j-f1/forked-JavaScriptKit

Open more actions menu
 
 

Repository files navigation

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-06-03-a/swift-wasm-DEVELOPMENT-SNAPSHOT-2020-06-03-a-osx.tar.gz
$ swift --version
Swift version 5.3-dev (LLVM 47c28180d7, Swift 5f96d487e0)
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)

const pet = {
  age: 3,
  owner: {
    name: "Mike",
  },
}

alert("JavaScript is running on browser!")

Can be written in Swift using JavaScriptKit

import JavaScriptKit

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

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

struct Owner: Codable {
  let name: String
}

struct Pet: Codable {
  let age: Int
  let owner: Owner
}

let jsPet = JSObject.global.pet
let swiftPet: Pet = try JSValueDecoder().decode(from: jsPet)

alert("Swift is running on browser!")

Please see Example directory for more information

About

Swift framework to interact with JavaScript through WebAssembly.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Swift 72.6%
  • TypeScript 15.5%
  • JavaScript 5.4%
  • C 5.0%
  • Makefile 1.4%
  • HTML 0.1%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.