Nuget package | CLI | Website | Try it online!
Library for translating c# to js, using Roslyn. The best way to find out if the library is for you is to try it online, just copy-paste c# code and see what it can or cannot translate. Also, check the warnings/notes below.
It is recommended to use the CLI/dotnet tool unless you want to write the front-end by yourself. Look for the implementation in the CLI, BWA app or the simple "Hello world" example below.
The CLI/dotnet tool is a simple cli front-end that behaves more or less like the dotnet cli, tsc cli, meson.
test262-parser(master): Only JS part (code is not public, yet. ES5 implemented) Total tests: 5363 | Passed: 2824 (52 %) | Failed: 2539
test262(es5 branch): Total tests: 11725 | Passed: 1272 (10 %)** | Failed: 10453
**Note: Tests run with "UseVarOverLet" option, using Jint as an engine.
Because translation is happening as-is, there are many (BIG!) limitations.
For example, namespaces are ignored, if you have 2 identical classes but in different namespaces, both will be translated with the same name!
Structs/Interfaces and many more are completely ignored.
The output is not tied to the ECMA standard, meaning if you use a static constructor in cs it will be translated as a static constructor even though it is ECMA 13th.
While the library provides a webapi by default, I do not consider it as a framework, it is just C# to JS translation. You are free to build on top of it if you want.
With all the notes/warnings above, what this library is useful for, I find it useful for is model/DTO translation as is. See the model example.
- Install the NuGet package or download a specific version.
- Skip this if using a Nuget package. Follow the instructions on how to add a project reference.
- In the Main method, add:
FileData file = new()
{
SourceStr = @"Console.WriteLine(""Hello world."");"
};
file = CSTOJS.Translate(file);
//TranslatedStr is in the same object FileData. The method Translate also returns the same object.
Console.WriteLine(file.TranslatedStr);- Run a program
- Console output should be:
console.log("Hello world.");FileData file = new()
{
OptionsForFile = new(){ Debug = true },
...
};
...- Dotnet tool/CLI for this library: https://github.com/TiLied/CSTOJS_CLI
- Tests: https://github.com/TiLied/CSTOJS_Tests
- Library for generating various things: https://github.com/TiLied/CSTOJS_GenLib
- Website/documentation: https://github.com/TiLied/CSTOJS_Pages
- Blazor WebAssembly app: https://github.com/TiLied/CSTOJS_BWA