CSharpToJavaScript 0.2.6

dotnet add package CSharpToJavaScript --version 0.2.6
                    
NuGet\Install-Package CSharpToJavaScript -Version 0.2.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CSharpToJavaScript" Version="0.2.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharpToJavaScript" Version="0.2.6" />
                    
Directory.Packages.props
<PackageReference Include="CSharpToJavaScript" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CSharpToJavaScript --version 0.2.6
                    
#r "nuget: CSharpToJavaScript, 0.2.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CSharpToJavaScript@0.2.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSharpToJavaScript&version=0.2.6
                    
Install as a Cake Addin
#tool nuget:?package=CSharpToJavaScript&version=0.2.6
                    
Install as a Cake Tool

CSharpToJavaScript

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.

Status

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.

A couple of notes

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.

Hello world

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.");
  • For options, look at the code or on the website.
  • To specify options (per file):
FileData file = new()
{
	OptionsForFile = new(){ Debug = true },
	...
};
...
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.6 115 11/27/2026
0.2.5 118 11/16/2026
0.2.4 175 8/31/2026
0.2.3 186 7/20/2026
0.2.2 177 5/18/2026
0.2.1 166 4/27/2026
0.2.0 159 4/20/2026
0.1.10 181 3/7/2026
0.1.9 161 3/4/2026
0.1.8 176 2/23/2026
0.1.7 169 2/23/2026
0.1.6 187 2/9/2026
0.1.5 194 1/26/2026
0.1.4 292 12/22/2025
0.1.3 355 12/15/2025
0.1.2 535 12/8/2025
0.1.1 304 11/24/2025
0.1.0 248 9/27/2025
0.0.10 379 9/15/2025
Loading failed