GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript
5.3.2601.1
dotnet add package GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript --version 5.3.2601.1
NuGet\Install-Package GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript -Version 5.3.2601.1
<PackageReference Include="GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript" Version="5.3.2601.1" />
<PackageVersion Include="GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript" Version="5.3.2601.1" />
<PackageReference Include="GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript" />
paket add GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript --version 5.3.2601.1
#r "nuget: GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript, 5.3.2601.1"
#:package GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript@5.3.2601.1
#addin nuget:?package=GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript&version=5.3.2601.1
#tool nuget:?package=GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript&version=5.3.2601.1
GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript
Repository Metadata
- Type: Library
- Language(s): C#
- Framework(s): .NET 9.0
- Database: None
Purpose & Context
What This Repository Does
This repository provides a JavaScript interpreter plugin for the GeeksCoreLibrary's Script Interpreters module. It enables server-side execution of JavaScript code within .NET applications, specifically for the Wiser CMS ecosystem. The library wraps the Jint JavaScript engine and exposes a clean, type-safe API for executing JavaScript code, managing state, and invoking functions from C# applications.
Business Value
The JavaScript interpreter allows Wiser applications to:
- Execute dynamic business logic stored in the database without redeployment
- Provide customers with scriptable configuration and validation rules
- Enable template-based content generation with JavaScript expressions
- Support complex calculations and transformations in product configurators
- Allow non-developers to customize application behavior through safe script execution
This is particularly valuable for Wiser's multi-tenant architecture where each customer may require different business rules and calculations without modifying the core platform.
Wiser Ecosystem Role
This library is a plugin module for GeeksCoreLibrary and serves as:
- A dependency for Wiser core applications that need JavaScript execution capabilities
- Part of the Script Interpreters module family (alongside potential Python, Lua, or other language interpreters)
- A bridge between database-stored templates/scripts and runtime execution
- A utility library used by product configurators, template engines, and validation systems
Core Functionality
Main Components
IJavaScriptService (Public Interface)
State Management:
SetValue(string name, object value)- Sets a global variable in the JavaScript engineGetValue(string name)- Retrieves a JavaScript variable as an objectGetValue<T>(string name)- Generic version with automatic type conversion
Script Execution:
Execute(string script)- Executes JavaScript statements without returning a valueEvaluate(string script)- Evaluates a JavaScript expression and returns the resultEvaluate<T>(string script)- Generic version with automatic type conversion and error handling
Function Invocation:
Invoke(string functionName, params object[] arguments)- Calls a JavaScript function by nameInvoke<T>(string functionName, params object[] arguments)- Generic version with type conversion
JavaScriptService (Core Implementation)
Implements HTML-to-PDF conversion using the Jint engine with security constraints:
- Security: Strict mode +
StringCompilationAllowed = false(disables eval) - GCL Integration: Exposes utility functions via global
GCLobject:GCL.ConvertToSeo(text)- Converts text to SEO-friendly URL slugGCL.EncryptWithAes(...)/GCL.DecryptWithAes(...)- AES encryptionGCL.ToSha512(text)- SHA-512 hashing
Installation & Setup
Prerequisites
- .NET 9.0 SDK or later
- GeeksCoreLibrary v5.3.2508.1 or compatible
- Jint v4.2.2 (automatically installed)
Installation
Install NuGet package:
dotnet add package GeeksCoreLibrary.Modules.ScriptInterpreters.JavaScript
Registration (automatic via ITransientService marker):
// In consuming application - no registration needed
// GeeksCoreLibrary auto-registers ITransientService implementations
public class MyController : Controller
{
private readonly IJavaScriptService _jsService;
public MyController(IJavaScriptService jsService)
{
_jsService = jsService; // Automatically injected
}
}
Basic Usage
using var jsService = serviceProvider.GetService<IJavaScriptService>();
// Execute and evaluate simple expression
var result = jsService.Evaluate<int>("2 + 2"); // Returns: 4
// Set values and use them
jsService.SetValue("name", "Wiser");
jsService.Execute("var greeting = 'Hello, ' + name + '!';");
var greeting = jsService.GetValue<string>("greeting"); // "Hello, Wiser!"
// Invoke functions
jsService.Execute("function multiply(a, b) { return a * b; }");
var product = jsService.Invoke<int>("multiply", 6, 7); // Returns: 42
// Use GCL utilities from JavaScript
jsService.Execute("var seoUrl = GCL.ConvertToSeo('Hello World! 2024');");
var seoUrl = jsService.GetValue<string>("seoUrl"); // "hello-world-2024"
Troubleshooting
Common Issues
eval is not allowed Error:
- Cause: Script uses
eval()ornew Function()(disabled for security) - Solution: Rewrite logic without dynamic code generation
ES6+ Syntax Errors:
- Cause: Jint only supports ECMAScript 5.1
- Solution: Rewrite using ES5 syntax (no arrow functions,
const,let, etc.)
InvalidCastException When Getting Values:
- Cause: Type mismatch between JavaScript and .NET
- Solution: Check JavaScript return type matches requested C# type
This documentation is part of the Wiser Platform knowledge base maintained by Happy Horizon B.V.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- GeeksCoreLibrary (>= 5.3.2601.1)
- Jint (>= 4.2.2)
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 |
|---|---|---|
| 5.3.2601.1 | 123 | 1/19/2026 |
| 5.3.2512.1 | 306 | 12/19/2025 |
| 5.3.2508.1 | 214 | 8/21/2025 |
| 5.3.2507.6 | 203 | 7/31/2025 |
| 5.3.2507.5 | 592 | 7/23/2025 |
| 5.3.2507.4 | 217 | 7/17/2025 |
| 5.3.2507.3 | 219 | 7/11/2025 |
| 5.3.2507.2 | 171 | 7/4/2025 |
| 5.3.2507.1 | 221 | 7/1/2025 |
| 5.3.2506.8 | 206 | 6/24/2025 |
| 5.3.2506.7 | 210 | 6/24/2025 |
| 5.3.2506.6 | 182 | 6/20/2025 |