https://github.com/bung87/ts2nim
Typescript to Nim transpiler
https://github.com/bung87/ts2nim
Last synced: 7 months ago
JSON representation
Typescript to Nim transpiler
- Host: GitHub
- URL: https://github.com/bung87/ts2nim
- Owner: bung87
- License: mit
- Created: 2020-05-05T15:43:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-25T04:07:16.000Z (almost 2 years ago)
- Last Synced: 2024-04-25T22:21:20.731Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 177 KB
- Stars: 45
- Watchers: 6
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-typescript-compilers - ts2nim
README
# ts2nim
[](https://www.npmjs.com/package/ts2nim)   Typescript to Nim transpiler
It also can translate js code with the Nim type `auto` as `typescript-estree` compatible with the js estree.
It identified the `.d.ts` file if the ast node is `TSMethodSignature` it will add `importcpp` pragma to translated `proc`, so it could be used as a wrapper generator.
## Motivation
Transpile nodejs modules, write in Typescript and transpile it to Nim, expand the Nim-Javascript backend ecosystem and so on.
Current goal is translating Typescript syntax into valid and pretty looking nim code. you may manually modify nim sources after translation. it just translate source code exclude dependency,even modules in nodejs std.
demo transpiled project:
[vscode-uri](https://github.com/bung87/vscode-uri)It can be easy to translate library processes like string manipulation, images, bytes and all these things.
## RoadMap
This project has two routes
1. Generate nim js bridge through typescript type difinition file.
2. Generate nim source code through typescript source file.### Todos
- [ ] Inferring js type (object or others)
- [ ] Inferring native type (eg. number is int or float)## Limitations
[assemblyscript basics](https://docs.assemblyscript.org/basics) described well, share same theory.
## Installation
`npm i ts2nim` or
`yarn add ts2nim`## Usage
`ts2nim -i inputFileOrDir -o outFileOrDir`
without param it will transpile current directory in place with extension `.nim`
## Translation
| origin | to | description |
| :-------------: | :----------: | :----------- |
| number | float | |
| boolean | bool | |
| interface,type,class | type | |
| Example() | newExample() | constructor for a class |
| let,var,const | var | const no-object -> const,others var |
| this | self | |
| null,undefinded | nil | |
| optinal param | none(T) | options module |
| T\|null,T\|undefinded | T | ref type|
| RestElement param | openArray[T] | |
| switch | case of | |
| Array | seq | |
| StringTemplate | fmt | strformat module |
| do while | doWhile | doWhile template |
| raise new T() | raise newException(T) | |
| .length | .len | |
| .push | .add | |
| fs.readFileSync | readFile | os module |
| path.join | / | os module |
| .some | .any | sequtils module |
| .sort | .sorted | algorithm module |
| async | {.async.} | asyncdispatch or asyncjs module |
| === | == | |
| !== | != | |
| && | and | |
| \|\| | or | |
| ! | not | |
| + | & or + | depends on a literal string or number found |
| delete | assign to nil | |
| extends A,B| ref object of A,B | Multiple Inheritance not supported in Nim |## Related Projects
[mcclure/dts2nim](https://github.com/mcclure/dts2nim)
## Projects use ts2nim
*Add by you*