Cocoar.JsEval.Module.AngleSharp 5.0.0

dotnet add package Cocoar.JsEval.Module.AngleSharp --version 5.0.0
                    
NuGet\Install-Package Cocoar.JsEval.Module.AngleSharp -Version 5.0.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.Module.AngleSharp" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cocoar.JsEval.Module.AngleSharp" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Cocoar.JsEval.Module.AngleSharp" />
                    
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.Module.AngleSharp --version 5.0.0
                    
#r "nuget: Cocoar.JsEval.Module.AngleSharp, 5.0.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.Module.AngleSharp@5.0.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.Module.AngleSharp&version=5.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Cocoar.JsEval.Module.AngleSharp&version=5.0.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
  • Sandboxed() + AllowOnly / DenyTypes for untrusted rules with real CLR objects
  • 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!"

Untrusted Rules

Two independent axes, and an untrusted script wants both. Sandboxed() governs what a script can do on its own — strict mode, no eval/Function, no reflection, and memory, recursion, stack, array and regex limits. AllowOnly and DenyTypes govern what it can reach: passing an object otherwise grants everything reachable from it.

services.AddJsEval(b => b
    .Sandboxed()                                   // hardens the runtime, latches
    .AllowOnly(a => a
        .Member((Customer c) => c.Name)
        .Member((Customer c) => c.Age))
    .DenyTypes(typeof(DbContext), typeof(IServiceProvider)));

Sandboxed() latches in both directions — EnableFetch() before or after it throws — so the guarantee never depends on the order the builder is written in. It hardens the runtime but does not narrow the object graph; that is what AllowOnly is for. Isolation between scripts is the engine instance: resolve a separate engine per script source.

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 for trusted integration scripts and provides the full module system. For tenant- or end-user-authored rules, resolve a Sandboxed() engine with an AllowOnly surface. Evaluate is a lightweight execution mode for scripts you control and know do not 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

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
5.0.0 76 8/10/2026
4.1.0 117 5/23/2026
4.1.0-beta.2 70 5/23/2026
4.1.0-beta.1 58 5/23/2026
4.0.0 108 5/6/2026
3.4.0-beta.4 52 5/6/2026
3.4.0-beta.3 51 5/6/2026
3.3.0 111 4/27/2026
3.3.0-beta.11 65 4/27/2026
3.3.0-beta.10 62 4/27/2026
3.3.0-beta.5 61 4/26/2026
3.3.0-beta.2 68 4/25/2026
3.3.0-beta.1 58 4/25/2026
3.2.0 110 4/24/2026
3.2.0-tsdefinition-short-na... 63 4/19/2026
3.1.4 102 4/20/2026
3.1.3 112 4/19/2026
3.1.2 103 4/18/2026
0.0.0-tsdefinition-short-na... 62 4/19/2026
0.0.0-tsdefinition-short-na... 68 4/19/2026
Loading failed