Features/v3 add short and full guid (#3800)
* add full guid and shortguid as javascript/jint functions with intellisense * add guid as string and rename other method
This commit is contained in:
parent
c81e328c8d
commit
95ca326133
|
|
@ -1,5 +1,6 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Elsa.Expressions.Contracts;
|
||||
using Elsa.Expressions.Models;
|
||||
using Elsa.Extensions;
|
||||
|
|
@ -74,12 +75,14 @@ public class JintJavaScriptEvaluator : IJavaScriptEvaluator
|
|||
|
||||
// Create variable & input setters and getters for each variable.
|
||||
CreateMemoryBlockAccessors(engine, context);
|
||||
|
||||
|
||||
engine.SetValue("isNullOrWhiteSpace", (Func<string, bool>)(value => string.IsNullOrWhiteSpace(value)));
|
||||
engine.SetValue("isNullOrEmpty", (Func<string, bool>)(value => string.IsNullOrEmpty(value)));
|
||||
engine.SetValue("parseGuid", (Func<string, Guid>)(value => Guid.Parse(value)));
|
||||
engine.SetValue("toJson", (Func<object, string>)(value => Serialize(value)));
|
||||
engine.SetValue("getShortGuid", (Func<string, string>)(value => Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", "")));
|
||||
engine.SetValue("getGuid", (Func<string, Guid>)(value => Guid.NewGuid()));
|
||||
engine.SetValue("getGuidString", (Func<string, string>)(value => Guid.NewGuid().ToString()));
|
||||
|
||||
// Add common .NET types.
|
||||
engine.RegisterType<DateTime>();
|
||||
|
|
|
|||
|
|
@ -61,7 +61,19 @@ internal class CommonFunctionsDefinitionProvider : FunctionDefinitionProvider
|
|||
.Name("parseGuid")
|
||||
.Parameter("value", "string")
|
||||
.ReturnType("Guid"));
|
||||
|
||||
|
||||
yield return CreateFunctionDefinition(builder => builder
|
||||
.Name("getShortGuid")
|
||||
.ReturnType("string"));
|
||||
|
||||
yield return CreateFunctionDefinition(builder => builder
|
||||
.Name("getGuid")
|
||||
.ReturnType("Guid"));
|
||||
|
||||
yield return CreateFunctionDefinition(builder => builder
|
||||
.Name("getGuidString")
|
||||
.ReturnType("string"));
|
||||
|
||||
yield return CreateFunctionDefinition(builder => builder
|
||||
.Name("toJson")
|
||||
.Parameter("value", "any")
|
||||
|
|
|
|||
Loading…
Reference in a new issue