Shift.js

raw JSON →
0.1.1 verified Fri May 01 auth: no javascript deprecated

A Swift to JavaScript transpiler written in JavaScript, version 0.1.1 (early development). It supports basic Swift data types, collection types, operators, control flow, and functions. The project provides a CLI tool and API, using Escodegen for code generation. It is in active development with limited language coverage and no recent updates.

error Cannot find module 'shift-js'
cause Package not installed globally or locally.
fix
Run 'npm install shift-js' or install globally with 'npm install -g shift.js' (note the dot).
error shift.transpile is not a function
cause Incorrect import; default export may be an object or class.
fix
Use 'const shift = require('shift-js'); const result = shift.transpile(code);'
error Unexpected token :
cause Transpiler does not support Swift type annotations.
fix
Remove type annotations from Swift code before transpiling.
deprecated Project is in early development and likely abandoned; no updates since 2015.
fix Consider using other transpilers like Swiftify or manual migration.
breaking Requires Node 4.0.0+; may not work with modern Node versions due to deprecated APIs.
fix Use Node 4.x or a compatible runtime; upgrade not recommended.
gotcha Only supports a subset of Swift; complex features like generics or protocols may fail.
fix Stick to basic Swift constructs or transpile manually.
deprecated Dependencies include Bluebird and Commander.js; these may be outdated with security vulnerabilities.
fix Audit dependencies or use isolated environment.
npm install shift.js
yarn add shift.js
pnpm add shift.js

Transpile a simple Swift function to JavaScript using Shift.js API.

const shift = require('shift-js');
const swiftCode = `
func greet(name: String) -> String {
    return "Hello, " + name + "!"
}
let result = greet(name: "World")
print(result)
`;
shift.transpile(swiftCode).then(js => {
    console.log(js);
}).catch(err => {
    console.error(err);
});