An extension library for Jint that adds Web API implementations such as ReadableStream, localStorage, fetch, setTimeout, etc.
dotnet add package Yilduzusing Jint;
using Yilduz;
using var cts = new CancellationTokenSource();
using var engine = new Engine((o) => o.CancellationToken(cts.Token)).InitializeWebApi(
new() { CancellationToken = cts.Token }
);
engine.Execute(
"""
console.log('Hello world!');
setTimeout(() => console.log('I can use `setTimeout`!'), 2000);
"""
);
cts.Cancel();Click to expand
- Aborting
-
AbortController -
AbortSignal
-
- Base64
-
atob() -
btoa()
-
- Compression
-
CompressionStream -
DecompressionStream
-
- Console
-
console
-
- Data
-
Blob -
Document -
File -
FileReader -
FileReaderSync -
FormData
-
- DOM
-
DOMError -
DOMException
-
- Encoding
-
TextDecoder -
TextDecoderStream -
TextEncoder -
TextEncoderStream
-
- Events
-
CloseEvent -
Event -
EventTarget -
MessageEvent -
ProgressEvent
-
- Network
-
fetch() -
Headers -
Request -
Response -
WebSocket -
XMLHttpRequest -
XMLHttpRequestEventTarget -
XMLHttpRequestUpload
-
- Streams
-
ByteLengthQueuingStrategy -
CountQueuingStrategy -
ReadableByteStreamController -
ReadableStream- Async iteration is not implemented yet in Jint
-
ReadableStreamBYOBReader -
ReadableStreamBYOBRequest -
ReadableStreamDefaultReader -
ReadableStreamDefaultController -
WritableStream -
WritableStreamDefaultWriter -
WritableStreamDefaultController -
TransformStream -
TransformStreamDefaultController
-
- Storages
-
localStorage -
sessionStorage
-
- Timers
-
setTimeout() -
setInterval() -
clearTimeout() -
clearInterval()
-
- URLs
-
URL -
URLSearchParams
-
Want to try these features right now?
Just use Yilduz.Repl, a JavaScript REPL (Read-Eval-Print-Loop) program with Web API support, syntax error hints and syntax highlighting. Grab the latest artifact from the build workflow.
The TextDecoder implementation supports common character encodings including UTF-8, UTF-16, ASCII, and ISO-8859-1.
If you need to use additional character encodings beyond the common ones, you'll need to install the System.Text.Encoding.CodePages NuGet package and register the encoding providers:
using System.Text;
var engine = new Engine().InitializeWebApi(new() { CancellationToken = token });
// engine.Evaluate("new TextDecoder('gb_2312').encoding"); // throws an error
// Register additional encoding providers
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
engine.Evaluate("new TextDecoder('gb_2312').encoding"); // = 'gbk'This enables support for legacy encodings such as Windows-1252, Shift-JIS, and other code page encodings.
By default, Yilduz supports the following compression formats specified in the WHATWG standard:
| Format | Underlying .NET Implementation | Note |
|---|---|---|
gzip |
System.IO.Compression.GZipStream |
|
deflate-raw |
System.IO.Compression.DeflateStream |
|
deflate |
System.IO.Compression.ZLibStream |
Available in .NET 6+ |
Additionally, you can completely customize the underlying compression implementations or add new formats (such as Brotli) by overriding Options.Compression.CompressorFactory and Options.Compression.DecompressorFactory during initialization. You can turn to CustomProviderTests.cs for examples of how to do this.
Some behaviors may differ slightly from Web specs because certain features wrap .NET types; we're working through these gaps.
WebSocket.extensionsis only available when using .NET 7.0 or later, since theClientWebSocket.HttpResponseHeadersproperty requires .NET 7.0+. On earlier versions, this value will always be an empty string ('').
It was chosen arbitrarily.
The name comes from a little-known alternative name for the North Star.
