Cocoar.JsEval.Engine 3.3.0

dotnet add package Cocoar.JsEval.Engine --version 3.3.0
                    
NuGet\Install-Package Cocoar.JsEval.Engine -Version 3.3.0
                    
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="Cocoar.JsEval.Engine" Version="3.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cocoar.JsEval.Engine" Version="3.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Cocoar.JsEval.Engine" />
                    
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 Cocoar.JsEval.Engine --version 3.3.0
                    
#r "nuget: Cocoar.JsEval.Engine, 3.3.0"
                    
#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 Cocoar.JsEval.Engine@3.3.0
                    
#: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=Cocoar.JsEval.Engine&version=3.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Cocoar.JsEval.Engine&version=3.3.0
                    
Install as a Cake Tool

Cocoar.JsEval

JavaScript/TypeScript execution library for .NET, built on Jint.

NuGet License

Features

  • JavaScript execution via Jint (ES2025 support)
  • Execution methods: ExecuteAsync(string) / ExecuteAsync(prepared module) (standard), Evaluate(string) / Evaluate(prepared), EvaluateAsync()
  • Pre-parsed scripts (Prepare() / PrepareModule()) for maximum throughput
  • TypeScript 6.0 transpilation with embedded compiler
  • fetch() API with opt-in sandboxing
  • Automatic .NET Task → JS Promise interop
  • console.log/warn/error/debug via ILogger
  • setTimeout/setInterval support
  • Extensible module system (HTTP, Database, SMTP, Templates, and more)
  • .d.ts generation for IntelliSense support
  • Built for .NET 10

Quick Start

dotnet add package Cocoar.JsEval.Engine

Basic JavaScript Execution

services.AddJsEval();
var engine = sp.GetRequiredService<JsEngine>();
engine.SetValue("name", "World");
engine.Evaluate("var greeting = 'Hello, ' + name + '!';");
var result = engine.GetValue<string>("greeting"); // "Hello, World!"

With ES Modules

services.AddJsEval(b => b
    .AddModule<CommonModule>()
    .AddModule<HttpModule>()
);
var engine = sp.GetRequiredService<JsEngine>();
await engine.ExecuteAsync(@"
    import * as common from 'common';
    export function newId() { return common.Guid.New().toString(); }
");
var id = engine.InvokeFunction("newId"); // fresh GUID each call

ES-module semantics: top-level code runs once per unique script on a given engine — repeated ExecuteAsync calls return the cached module namespace. Put per-call work inside exported functions and invoke them via InvokeFunction. For true per-call re-execution use the lightweight Evaluate(string) path.

Pre-Parsed Scripts (for repeated execution)

// Parse once (thread-safe, cacheable)
var prepared = JsEngine.Prepare("query.WhereResponsible(ctx.UserId);");

// Execute many times — no re-parsing
engine.SetValue("ctx", accessContext);
engine.SetValue("query", queryBuilder);
engine.Evaluate(prepared);

TypeScript Transpilation

dotnet add package Cocoar.JsEval.TypeScript
services.AddTsTranspiler();
var transpiler = sp.GetRequiredService<TsTranspiler>();
var js = transpiler.Transpile(tsCode);  // transpile once
await engine.ExecuteAsync(js);          // execute

fetch()

services.AddJsEval(b => b.EnableFetch());
const response = await fetch('https://api.example.com/data');
const body = await response.text();
console.log(response.status, response.ok);

.NET async → JS Promise (automatic)

engine.SetValue("loadData", new Func<string, Task<string>>(async id => {
    return await db.FindAsync(id);
}));
const data = await loadData('item-123'); // .NET Task becomes a Promise

Execution Methods

Method Module System async Prepared Use Case
ExecuteAsync(string) Yes Yes No Standard -- use when you don't know what's in the script
ExecuteAsync(JsPreparedModule) Yes Yes Yes Pre-parsed module -- reuse across calls
Evaluate(string) No No No Lightweight sync -- when you control the script
Evaluate(JsPreparedScript) No No Yes Max performance -- pre-parsed, reusable, no module system
EvaluateAsync(string) No Yes No Lightweight async -- no modules but needs await

ExecuteAsync is the default/standard method -- it provides the full module system and is always safe. Evaluate is a conscious opt-in for a restricted execution mode -- choose it when you know your scripts don't need modules.

Packages

Package Description
Cocoar.JsEval Core: interfaces, helpers, JsFunction
Cocoar.JsEval.Engine JsEngine + fetch() + DI registration
Cocoar.JsEval.TypeScript TypeScript 6.0 transpiler
Cocoar.JsEval.TsDefinition .d.ts generation for IntelliSense
Cocoar.JsEval.Linq JS arrow functions → real Expression trees for Marten / EF / LINQ2DB
Cocoar.JsEval.Module.Common Guid, Sleep, Random
Cocoar.JsEval.Module.Http Fluent HTTP client
Cocoar.JsEval.Module.Database SQL Server + PostgreSQL
Cocoar.JsEval.Module.Smtp Email via MailKit
Cocoar.JsEval.Module.AngleSharp HTML parsing
Cocoar.JsEval.Module.Template Scriban templates
Cocoar.JsEval.Module.Logging Microsoft.Extensions.Logging
Cocoar.JsEval.Module.VirtualFileSystem Zio VFS

License

Apache-2.0 — COCOAR e.U.

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 (2)

Showing the top 2 NuGet packages that depend on Cocoar.JsEval.Engine:

Package Downloads
Cocoar.JsEval.TsDefinition

.d.ts definition generation for Cocoar.JsEval IntelliSense support

Cocoar.JsEval.Linq

Translates JavaScript arrow functions from Jint into real .NET Expression trees so any IQueryable LINQ provider (Marten, EF Core, LINQ2DB, ...) can convert them to native queries. Includes natural-name extension methods and property-dependency collector.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.3.0 114 4/27/2026
3.3.0-beta.11 50 4/27/2026
3.3.0-beta.10 68 4/27/2026
3.3.0-beta.5 44 4/26/2026
3.3.0-beta.2 47 4/25/2026
3.3.0-beta.1 48 4/25/2026
3.2.0 106 4/24/2026
3.2.0-tsdefinition-short-na... 45 4/19/2026
3.1.4 182 4/20/2026
3.1.3 107 4/19/2026
3.1.2 101 4/18/2026
3.1.1 103 4/18/2026
3.1.0 108 4/17/2026
3.0.0 100 4/17/2026
2.1.0-alpha.1 47 4/17/2026
2.0.0 114 4/17/2026
1.0.0 100 4/15/2026
0.2.0-alpha.4 56 4/15/2026
0.0.0-tsdefinition-short-na... 51 4/19/2026
0.0.0-tsdefinition-short-na... 53 4/19/2026