transplant-js

Write strictly-typed Javascript code

Usage no npm install needed!

<script type="module">
  import transplantJs from 'https://cdn.skypack.dev/transplant-js';
</script>

README

What is this ?

Transplant.js ( or Tx.js ) is a strict syntactical superset of TypeScript.
It uses “types on the left”-style declarations and the classic C/C++/Java types like int, double, str and bool.

Tx.js files can be created with the .tx extension.

You can read the Docs here.




Installation

Tx.js uses the TypeScript compiler so make sure you have it installed aswell

# Locally in your project
$ npm install -D typescript
$ npm install -D transplant-js

# Or globally with TypeScript (Recommended)
$ npm install -g typescript
$ npm install -g transplant-js

How to run

After installation, you can use the Transplant.js compiler txc
To compile test.tx run

$ txc test.tx

This command will create a test.ts and a test.js file. You can do whatever you want with them! 🥳

  • Transplant.js always tries to keep the same file name.
  • Error handling is done by the TypeScript compiler, except input errors.

How it works

// Write your code in Tx.js
    const int x = 10;
    str fact = 'Tx.js is awesome!';
    int[] myList = [ 3, 2, 1 ];
// The Tx compiler converts it to TypeScript
    const x: number = 10;
    let fact: string = 'Tx.js is awesome!';
    let myList: number[] = [ 3, 2, 1 ];
// Then the TypeScript compiler does the dirty job to convert it to JavaScript
    const x = 10;
    let fact = 'Tx.js is awesome!';
    let myList = [ 3, 2, 1 ];

License

This project is licensed under the MIT license. For more information, see the LICENSE file.