Add toJson JS function
The Jint implementation of JSON.stringify only supports a limited set of objects (not .NET LocalDate for example)
This commit is contained in:
parent
e918bc9301
commit
e3deafedf3
|
|
@ -1,4 +1,5 @@
|
|||
using Elsa.Expressions.Models;
|
||||
using System.Text.Json;
|
||||
using Elsa.Expressions.Models;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.JavaScript.Notifications;
|
||||
using Elsa.JavaScript.Options;
|
||||
|
|
@ -61,6 +62,7 @@ public class JintJavaScriptEvaluator : IJavaScriptEvaluator
|
|||
|
||||
engine.SetValue("isNullOrWhiteSpace", (Func<string, bool>)string.IsNullOrWhiteSpace);
|
||||
engine.SetValue("isNullOrEmpty", (Func<string, bool>)string.IsNullOrEmpty);
|
||||
engine.SetValue("toJson", (Func<object, string>)(value => JsonSerializer.Serialize(value)));
|
||||
|
||||
// Add common .NET types.
|
||||
engine.RegisterType<DateTime>();
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ internal class CommonFunctionDefinitionProvider : FunctionDefinitionProvider
|
|||
.Parameter("value", "string")
|
||||
.ReturnType("boolean"));
|
||||
|
||||
yield return CreateFunctionDefinition(builder => builder
|
||||
.Name("toJson")
|
||||
.Parameter("value", "any")
|
||||
.ReturnType("string"));
|
||||
|
||||
// Variable getter and setters.
|
||||
foreach (var variable in context.Variables)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue