Cocoar.JsEval.Expressions 1.0.0

dotnet add package Cocoar.JsEval.Expressions --version 1.0.0
                    
NuGet\Install-Package Cocoar.JsEval.Expressions -Version 1.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.Expressions" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cocoar.JsEval.Expressions" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Cocoar.JsEval.Expressions" />
                    
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.Expressions --version 1.0.0
                    
#r "nuget: Cocoar.JsEval.Expressions, 1.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.Expressions@1.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.Expressions&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Cocoar.JsEval.Expressions&version=1.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)
  • Four execution methods: ExecuteAsync() (standard), Evaluate(), Evaluate(prepared), EvaluateAsync()
  • Pre-parsed scripts (Prepare()) 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
  • IJsEngine interface for testability and mocking
  • Built for .NET 10

Quick Start

dotnet add package Cocoar.JsEval.Engine

Basic JavaScript Execution

services.AddJsEval();
var engine = sp.GetRequiredService<IJsEngine>();
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<IJsEngine>();
await engine.ExecuteAsync(@"
    import * as common from 'common'
    export const id = common.Guid.New();
");

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
Evaluate(string) No No No Lightweight sync -- when you control the script
Evaluate(JsPreparedScript) No No Yes Max performance -- pre-parsed, reusable
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.Expressions Expression Tree helpers for LINQ-compatible filters
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.
  • net10.0

    • No dependencies.

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
1.0.0 102 4/15/2026