{"id":13672647,"url":"https://github.com/jectivex/JXKit","last_synced_at":"2025-04-27T22:32:32.683Z","repository":{"id":58893894,"uuid":"370185302","full_name":"jectivex/JXKit","owner":"jectivex","description":"The pure swift interface to JavaScriptCore for iOS, macOS, tvOS, and Linux","archived":false,"fork":false,"pushed_at":"2025-03-17T12:35:08.000Z","size":1393,"stargazers_count":66,"open_issues_count":4,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T14:07:26.936Z","etag":null,"topics":["hacktoberfest","ios","javascriptcore","swift","swift-library","swift-linux"],"latest_commit_sha":null,"homepage":"https://www.jective.org/JXKit/documentation/jxkit/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jectivex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.LGPL","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-24T00:25:18.000Z","updated_at":"2025-03-17T12:31:59.000Z","dependencies_parsed_at":"2022-09-09T21:31:33.797Z","dependency_job_id":null,"html_url":"https://github.com/jectivex/JXKit","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jectivex%2FJXKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jectivex%2FJXKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jectivex%2FJXKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jectivex%2FJXKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jectivex","download_url":"https://codeload.github.com/jectivex/JXKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251219601,"owners_count":21554444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","ios","javascriptcore","swift","swift-library","swift-linux"],"created_at":"2024-08-02T09:01:43.023Z","updated_at":"2025-04-27T22:32:30.632Z","avatar_url":"https://github.com/jectivex.png","language":"Swift","readme":"# JXKit\n\n[![Build Status][GitHubActionBadge]][ActionsLink]\n[![Swift5 compatible][Swift5Badge]][Swift5Link] \n![Platform][SwiftPlatforms]\n\u003c!-- [![](https://tokei.rs/b1/github/jectivex/JXKit)](https://github.com/jectivex/JXKit) --\u003e\n\nJXKit is a cross-plarform swift module for interfacing with\n`JavaScriptCore`. It provides a fluent API for working with an embedded\n[`JXContext`](https://www.jective.org/JXKit/documentation/jxkit/jxcontext),\nincluding script evaluation, error handling, and Codable mashalling.\n\nJXKit is cross-platform for Darwin (macOS/iOS) and Linux,\nwith experimental support for Windows and Android.\n\nJSC to be used on platforms where the Objective-C runtime is unavailable (e.g., Linux).\n\n\n## API\n\nBrowse the [API Documentation].\n\n### Direct function invocation\n\nFunctions can be accessed (and cached) to be invoked directly with codable arguments:\n\n```swift\nlet context = JXContext()\nlet hypot = try context.global[\"Math\"][\"hypot\"]\nassert(hypot.isFunction == true)\nlet result = try hypot.call(withArguments: try [context.encode(3), context.encode(4)])\nlet hypotValue = try result.double\nassert(hypotValue == 5.0)\n```\n\n### Codable passing\n\nJXKit supports encoding and decoding Swift types directly into the `JXValue` instances, which enables `Codable`  instances to be passed back and forth to the virtual machine with minimal overhead. Since encoding \u0026 decoding doesn't use JSON `stringify` \u0026 `parse`, this can lead to considerable performance improvements when interfacing between Swift \u0026 JS.\n\nThe above invocation of `Math.hypot` can instead be performed by wrapping the arguments in an `Encodable` struct, and returning a `Decodable` value. \n\n```swift\n/// An example of invoking `Math.hypot` in a wrapper function that takes an encodable argument and returns a Decodable retult.\nstruct AB: Encodable { let a, b: Double }\nstruct C: Decodable { let c: Double }\n\nlet context = JXContext()\n\nlet hypot = try context.eval(\"(function(args) { return { c: Math.hypot(args.a, args.b) }; })\")\nassert(hypot.isFunction == true)\n\nlet result: C = try hypot.call(withArguments: [context.encode(AB(a: 3, b: 4))]).toDecodable(ofType: C.self)\nassert(result.c == 5)\n```\n\n### JavaScriptCore Compatibility\n\nThe JXKit API is a mostly drop-in replacement for the Objective-C `JavaScriptCore` framework available on most Apple devices. E.g., the following JavaScriptCore code:\n\n```swift\nimport JavaScriptCore\n\nlet jsc = JSContext()\nlet value: JSValue = jsc.evaluateScript(\"1+2\")\nassert(value.int == 3)\n```\n\nbecomes:\n\n```swift\nimport JXKit\n\nlet jxc = JXContext()\nlet value: JXValue = try jxc.eval(\"1+2\")\nassert(try value.int == 3)\n```\n\n## Installation\n\n\u003e _Note:_ Requires Swift 5.5+\n\n### Swift Package Manager\n\nThe [Swift Package Manager][] is a tool for managing the distribution of\nSwift code.\n\n1. Add the following to your `Package.swift` file:\n\n  ```swift\n  // swift-tools-version:5.6\n  import PackageDescription\n\n  let package = Package(\n      name: \"MyPackage\",\n      products: [\n          .library(\n              name: \"MyPackage\",\n              targets: [\"MyPackage\"]),\n      ],\n      dependencies: [\n          .package(name: \"JXKit\", url: \"https://github.com/jectivex/JXKit.git\", .upToNextMajor(from: \"3.0.0\")),\n      ],\n      targets: [\n          .target(\n              name: \"MyPackage\",\n              dependencies: [\"JXKit\"]),\n              .testTarget(\n                  name: \"MyPackageTests\",\n                  dependencies: [\"MyPackage\"]),\n          ]\n      )\n  ```\n\n2. Build your project:\n\n  ```sh\n  $ swift build\n  ```\n\n## License\n\nLike the [JavaScriptCore](https://webkit.org/licensing-webkit/) framework\nupon which it is built, JXKit is licensed under the GNU LGPL license.\nSee [LICENSE.LGPL](LICENSE.LGPL) for details.\n\n## Related\n\nProjects that are based on JXKit:\n\n - [Jack][]: Cross-platform framework for scripting `Combine.ObservableObject` and SwiftUI (LGPL)\n\n## Dependencies\n\n - [JavaScriptCore][]: Cross-platform JavaScript engine (LGPL)[^1]\n\n[^1]: JavaScriptCore is included with macOS and iOS as part of the embedded [WebCore](https://webkit.org/licensing-webkit/) framework (LGPL); on Linux JXKit uses [WebKit GTK JavaScriptCore](https://webkitgtk.org/).\n\n\n[Swift Package Manager]: https://swift.org/package-manager\n[API Documentation]: https://www.jective.org/JXKit/documentation/jxkit/\n\n[ProjectLink]: https://github.com/jectivex/JXKit\n[ActionsLink]: https://github.com/jectivex/JXKit/actions\n[API Documentation]: https://www.jective.org/JXKit/documentation/jxkit/\n\n[Swift]: https://swift.org/\n[OpenCombine]: https://github.com/OpenCombine/OpenCombine\n[JXBridge]: https://github.com/jectivex/JXBridge\n[JavaScriptCore]: https://trac.webkit.org/wiki/JavaScriptCore\n\n[GitHubActionBadge]: https://img.shields.io/github/workflow/status/jectivex/JXKit/JXKit%20CI\n\n[Swift5Badge]: https://img.shields.io/badge/swift-5-orange.svg?style=flat\n[Swift5Link]: https://developer.apple.com/swift/\n[SwiftPlatforms]: https://img.shields.io/badge/Platforms-macOS%20|%20iOS%20|%20tvOS%20|%20Linux-teal.svg\n\n## TODO\n\n- Consider evalClosureAsync variant for async code.\n- Better reporting of errors from async code / Promises.\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjectivex%2FJXKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjectivex%2FJXKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjectivex%2FJXKit/lists"}