Jint.CommonJS
1.0.0
See the version list below for details.
dotnet add package Jint.CommonJS --version 1.0.0
NuGet\Install-Package Jint.CommonJS -Version 1.0.0
<PackageReference Include="Jint.CommonJS" Version="1.0.0" />
paket add Jint.CommonJS --version 1.0.0
#r "nuget: Jint.CommonJS, 1.0.0"
// Install Jint.CommonJS as a Cake Addin #addin nuget:?package=Jint.CommonJS&version=1.0.0 // Install Jint.CommonJS as a Cake Tool #tool nuget:?package=Jint.CommonJS&version=1.0.0
Jint.CommonJS
What's a GitHub project without build badges?
Jint.CommonJS is an extremely simple CommonJS-compatible module loader for the Jint .NET Javascript Engine. It's written in .NET core 2.0 and should be compatible with all .NET frameworks that Jint targets. It allows you to require JavaScript modules from other modules in the Jint interpreter using the familiar require
function we all know and love.
Every loaded module is wrapped in the following closure:
(function(module, exports, __dirname, require))
...and thus module bodies are not globally scoped.
module
points to the CLR module instanceexports
points to the module's public API__dirname
is the directory that this module resides inrequire
is a function which loads other modules relative to this module's directory
The library is MIT licensed.
A note about Node.JS compatibilty
You are not able to load npm packages with Jint.CommonJS. Although the library loads modules in relatively the same format at NodeJS's Module specification, there are some important distinctions. The library does not support node_modules, or reading package.json files for modules.
Features
require
another JavaScript module from a JavaScript file withrequire('./module')
require
JSON withrequire('./file.json')
require
modules from other modules- A small but succinct unit test suite.
Using the library
- Import the project reference via NuGet, or by cloning and building the project directly
- Import the
Jint.CommonJS
namespace in your code - Use the
CommonJS()
extension method onJint.Engine
to enable CommonJS functionality
Example
The following example runs a main module from the C# program's current directory.
using Jint;
using Jint.CommonJS;
public static class Program
{
public static Engine engine = new Engine();
public static void Main(string[] args)
{
// Creates a new Jint instance and runs the myModule.js file in the program's
// current working directory.
Jint.Native.JsValue exports = engine.CommonJS().RunMain("./myModule");
}
}
myModule.js
exports.value = require('./myOtherModule');
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- jint (>= 2.11.58)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Jint.CommonJS:
Package | Downloads |
---|---|
Jist.Next
The next generation of server-sided economy for TShock Servers |
GitHub repositories
This package is not used by any popular GitHub repositories.