Jint.CommonJS 1.0.0

Package Description

There is a newer version of this package available.
See the version list below for details.
Install-Package Jint.CommonJS -Version 1.0.0
dotnet add package Jint.CommonJS --version 1.0.0
<PackageReference Include="Jint.CommonJS" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jint.CommonJS --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Jint.CommonJS

What's a GitHub project without build badges? Build status

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 instance
  • exports points to the module's public API
  • __dirname is the directory that this module resides in
  • require 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 with require(&#39;./module&#39;)
  • require JSON with require(&#39;./file.json&#39;)
  • require modules from other modules
  • A small but succinct unit test suite.

Using the library

  1. Import the project reference via NuGet, or by cloning and building the project directly
  2. Import the Jint.CommonJS namespace in your code
  3. Use the CommonJS() extension method on Jint.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');

Jint.CommonJS

What's a GitHub project without build badges? Build status

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 instance
  • exports points to the module's public API
  • __dirname is the directory that this module resides in
  • require 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 with require(&#39;./module&#39;)
  • require JSON with require(&#39;./file.json&#39;)
  • require modules from other modules
  • A small but succinct unit test suite.

Using the library

  1. Import the project reference via NuGet, or by cloning and building the project directly
  2. Import the Jint.CommonJS namespace in your code
  3. Use the CommonJS() extension method on Jint.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');

  • .NETStandard 2.0

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.

Version History

Version Downloads Last updated
1.0.14 1,143 4/22/2018
1.0.13 490 4/21/2018
1.0.12 513 4/21/2018
1.0.11 537 4/21/2018
1.0.10 533 4/7/2018
1.0.9 529 3/24/2018
1.0.8 497 3/24/2018
1.0.7 520 3/23/2018
1.0.0 539 3/23/2018
Show less