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
<PackageReference Include="Cocoar.JsEval.Engine" Version="3.3.0" />
<PackageVersion Include="Cocoar.JsEval.Engine" Version="3.3.0" />
<PackageReference Include="Cocoar.JsEval.Engine" />
paket add Cocoar.JsEval.Engine --version 3.3.0
#r "nuget: Cocoar.JsEval.Engine, 3.3.0"
#:package Cocoar.JsEval.Engine@3.3.0
#addin nuget:?package=Cocoar.JsEval.Engine&version=3.3.0
#tool nuget:?package=Cocoar.JsEval.Engine&version=3.3.0
Cocoar.JsEval
JavaScript/TypeScript execution library for .NET, built on Jint.
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→ JSPromiseinterop console.log/warn/error/debugviaILoggersetTimeout/setIntervalsupport- Extensible module system (HTTP, Database, SMTP, Templates, and more)
.d.tsgeneration 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
ExecuteAsynccalls return the cached module namespace. Put per-call work inside exported functions and invoke them viaInvokeFunction. For true per-call re-execution use the lightweightEvaluate(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 | Versions 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. |
-
net10.0
- Cocoar.JsEval (>= 3.3.0)
- Jint (>= 4.8.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
- Nito.AsyncEx.Tasks (>= 5.1.2)
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 |