ECMASwift
A tiny Javascript runtime for iOS and macOS
Install / Use
/learn @theolampert/ECMASwiftREADME
ECMASwift
ECMASwift intends to implement a tiny subset of Browser APIs (mostly networking related) to make code sharing between iOS/macOS apps and the web easier.
Features
ECMASwift exposes the following browser APIs to JavascriptCore, some of these are incomplete, contributions welcome.
- Blob
- Console
- Crypto
- Fetch
- FormData
- Headers
- Request
- TextEncoder
- Timers
- URL
- URLSearchParams
Examples
In Javascript:
// Define an async function to fetch some dummy data in Javascript
async function fetchProducts() {
try {
const res = await fetch("https://google.com")
return await res.json()
} catch(error) {
console.log(error)
}
}
In Swift:
import ECMASwift
import JavaScriptCore
// Initialise the runtime
let runtime = JSRuntime()
// Load the javascript source file defined above, alternatively JS can be written inline.
let javascriptSource = try! String(contentsOfFile: "./example.js")
// Evaluate the script
_ = runtime.context.evaluateScript(javascriptSource)
// Call the `fetchProducts` function defined in the source file.
let result = try! await runtime.context.callAsyncFunction(key: "fetchProducts")
// Print the result
print(result.toString())
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
