Registry / serialization / swift-js

swift-js

JSON →
library0.1.0jsnpmunverified

A Swift-to-JavaScript transpiler (v0.1.0) that converts a subset of Swift syntax into JavaScript. Provides basic support for classes, functions, variables, and control flow. Not actively maintained; experimental status. Differentiators vs alternative transpilers (e.g., Kotlin/JS, Scala.js) include minimal dependencies and a simple CLI workflow, but lacks robust error handling, Unicode support, and standard library mapping. Suitable for proof-of-concept projects only.

npm install swift-js
INSTALL
IMPORT
SIG · SWIFT-JS
S
swift-js
serializationjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

transpile
import { transpile } from 'swift-js';
const swift = require('swift-js');
ESM-only support; CJS require() fails due to missing default export.
default
import swiftjs from 'swift-js';
const swiftjs = require('swift-js').default;
Default export is the transpile function; named export also available.
SwiftJSTranspiler
import { SwiftJSTranspiler } from 'swift-js';
const Transpiler = require('swift-js').SwiftJSTranspiler;
Class export for advanced usage; requires ESM import.

Basic example transpiling a Swift function to JavaScript, including error handling for transpilation failures.

import { transpile } from 'swift-js'; const swiftCode = ` func greet(name: String) -> String { return "Hello, \(name)!" } print(greet(name: "World")) `; try { const jsCode = transpile(swiftCode); console.log(jsCode); } catch (err) { console.error('Transpilation error:', err.message); }
swift-js --version
Debug
Known issues
gotchaSwift string interpolation escaped incorrectly in JavaScript output.
fix
Manually replace \(...) with template literal syntax ${...} after transpilation.
affects: >=0.0.1
gotchaDoes not support Swift's Optional types; nil may be mapped to undefined incorrectly.
fix
Handle undefined values manually in generated JS code.
affects: >=0.0.1
deprecatedPackage has not been updated since 2020; consider using modern alternatives like Kotlin/JS or TypeScript.
fix
Migrate to a supported transpiler.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'swift-js'
Package not installed or not in a valid npm registry.
fix
Install via 'npm install swift-js' from npm registry.
'require' is not defined in ES module scope
Using CommonJS require() with an ESM-only package.
fix
Use 'import { transpile } from 'swift-js';' or set 'type': 'module' in package.json.
Unexpected token: '('
Swift syntax not supported by the transpiler (e.g., closures with shorthand arguments).
fix
Rewrite unsupported Swift constructs using basic function definitions.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
swift-js — npm install swift-js · libregistry