Skip to content
sebastienrosPublic

About

Javascript Interpreter for .NET

Resources

Security policy

Stars

4.7k stars

Watchers

135 watching

Forks

Latest commit

 

History

3,021 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build NuGet Feedz

Jint

Jint is a modern ECMAScript interpreter for .NET. It runs JavaScript directly in your process without native dependencies, bytecode generation, or a separate runtime.

Jint targets .NET Framework 4.7.2, .NET Standard 2.0/2.1, .NET 8, and .NET 10. Start with the documentation or install the core package:

dotnet add package Jint

Quick start

The examples below assume using Jint;.

Evaluate JavaScript

var engine = new Engine();
var result = engine.Evaluate("40 + 2").AsNumber();

Expose .NET and call JavaScript

var engine = new Engine()
    .SetValue("log", new Action<string>(Console.WriteLine))
    .Execute("""
        function greet(name) {
            const message = `Hello, ${name}!`;
            log(message);
            return message;
        }
        """);

var greeting = engine.Invoke("greet", "Ada").AsString();

Prepare code that runs repeatedly

var script = Engine.PrepareScript(
    "items.reduce((sum, value) => sum + value, 0)",
    source: "sum.js",
    strict: true);

var engine = new Engine();
engine.SetValue("items", new[] { 1, 2, 3 });

var total = engine.Evaluate(in script).AsNumber();

Prepared