From 7be3d6cfe1f0e9f8e177b619790049d0b7064b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Can=20Bak=C4=B1r?= Date: Wed, 21 Oct 2026 00:09:41 +0300 Subject: [PATCH 1/2] docs: fix readme typos --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0921183..1cf8bcf 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,12 @@ func main() { for matcherName, expression := range expressions { compiledExpression, err := govaluate.NewEvaluableExpressionWithFunctions(expression, dsl.DefaultHelperFunctions) if err != nil { - fmt.Printf("Failed to compile expresion: %v\n", expression) + fmt.Printf("Failed to compile expression: %v\n", expression) } result, err := compiledExpression.Evaluate(data) if err != nil { - fmt.Printf("Failed to evaluate expresion: %v\n", expression) + fmt.Printf("Failed to evaluate expression: %v\n", expression) } if result == true { @@ -143,7 +143,7 @@ func main() { | trim_suffix(input, suffix string) string | Returns input without the provided trailing suffix string | `trim_suffix("aaHelloaa", "aa")` | `aaHello` | | uniq(input string) string
uniq(input number) string
uniq(elements ...interface{}) []interface{} | Removes duplicate characters from a string, digits from a number, or elements from a list | `uniq("aabbcc")`
`uniq(112233)`
`uniq("b", "a", "b")` | `abc`
`123`
`["b", "a"]` | | unix_time(optionalSeconds uint) float64 | Returns the current Unix time (number of seconds elapsed since January 1, 1970 UTC) with the added optional seconds | `unix_time(10)` | `1639568278` | -| unpack(format string, sequence string/bytes) {}interface | Returns the result of python binary unpack for the first operand in the sequence (endianess+operand) | `unpack('>I', '\xac\xd7\t\xd0')` | `-272646673` | +| unpack(format string, sequence string/bytes) {}interface | Returns the result of python binary unpack for the first operand in the sequence (endianness+operand) | `unpack('>I', '\xac\xd7\t\xd0')` | `-272646673` | | url_decode(input string) string | URL decodes the input string | `url_decode("https:%2F%2Fprojectdiscovery.io%3Ftest=1")` | `https://projectdiscovery.io?test=1` | | url_encode(s string, optionalEncodeAllSpecialChars bool) string | URL encodes the input string. When optionalEncodeAllSpecialChars is true, encodes all special characters | `url_encode("https://projectdiscovery.io/test?a=1")`
`url_encode("test@example.com", true)` | `https%3A%2F%2Fprojectdiscovery.io%2Ftest%3Fa%3D1`
`test%40example%2Ecom` | | wait_for(seconds uint) | Pauses the execution for the given amount of seconds | `wait_for(10)` | `true` | @@ -174,7 +174,7 @@ func main() { **Binary pack/unpack** -The gostruct package provides functionality for converting Go values represented as byte slices. It uses format strings to describe the layout of the Go structs. The format characters include boolean, big endian, little endian, int, float32, float64, and string types with different packed sizes. Currently, only binary unpack of the first operand after endianess has been supported. +The gostruct package provides functionality for converting Go values represented as byte slices. It uses format strings to describe the layout of the Go structs. The format characters include boolean, big endian, little endian, int, float32, float64, and string types with different packed sizes. Currently, only binary unpack of the first operand after endianness has been supported. #### JSON helper functions From 5fa182786f45f6f5d3334ad59aa2d7b0fadd523c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Can=20Bak=C4=B1r?= Date: Wed, 21 Oct 2026 00:09:44 +0300 Subject: [PATCH 2/2] feat: add to_slug helper --- README.md | 1 + dsl.go | 7 +++++++ dsl_test.go | 3 +++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 1cf8bcf..e0560a1 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ func main() { | to_bool(input interface{}) bool | Converts the input to a boolean value | `to_bool("true")`
`to_bool(1)`
`to_bool("")` | `true`
`true`
`false` | | to_lower(input string) string | Transforms the input into lowercase characters | `to_lower("HELLO")` | `hello` | | to_number(input interface{}) interface{} | Converts the input to a number | `to_number("123")` | `123` | +| to_slug(input string) string | Replaces every run of non-letter, non-digit characters with a single hyphen, trimming leading and trailing ones | `to_slug("Screenshot https://example.com")` | `Screenshot-https-example-com` | | to_string(input interface{}) interface{} | Converts the input to a string | `to_string(123)` | `"123"` | | to_title(s, optionalLang string) string | Converts string to title case with optional language parameter | `to_title("hello world")` | `Hello World` | | to_unix_time(input string, layout string) int | Parses a string date time using default or user given layouts, then returns its Unix timestamp | `to_unix_time("2022-01-13T16:30:10+00:00")`
`to_unix_time("2022-01-13 16:30:10")`
`to_unix_time("13-01-2022 16:30:10". "02-01-2006 15:04:05")` | `1642091410` | diff --git a/dsl.go b/dsl.go index 43fdd67..6222761 100644 --- a/dsl.go +++ b/dsl.go @@ -33,6 +33,7 @@ import ( "strconv" "strings" "time" + "unicode" "github.com/Mzack9999/gcache" "github.com/asaskevich/govalidator" @@ -173,6 +174,12 @@ func init() { MustAddFunction(NewWithPositionalArgs("to_lower", 1, true, func(args ...interface{}) (interface{}, error) { return strings.ToLower(toString(args[0])), nil })) + MustAddFunction(NewWithPositionalArgs("to_slug", 1, true, func(args ...interface{}) (interface{}, error) { + words := strings.FieldsFunc(toString(args[0]), func(r rune) bool { + return !unicode.IsLetter(r) && !unicode.IsDigit(r) + }) + return strings.Join(words, "-"), nil + })) MustAddFunction(NewWithMultipleSignatures("sort", []string{ "(input string) string", "(input number) string", diff --git a/dsl_test.go b/dsl_test.go index a2c0f71..e97dbbf 100644 --- a/dsl_test.go +++ b/dsl_test.go @@ -314,6 +314,7 @@ func TestGetPrintableDslFunctionSignatures(t *testing.T) { to_bool(arg1 interface{}) interface{} to_lower(arg1 interface{}) interface{} to_number(arg1 interface{}) interface{} + to_slug(arg1 interface{}) interface{} to_string(arg1 interface{}) interface{} to_title(s, optionalLang string) string to_unix_time(input string, optionalLayout string) int64 @@ -384,6 +385,8 @@ func TestDslExpressions(t *testing.T) { `to_bool(0)`: false, `to_bool("x")`: false, `to_lower("HELLO")`: "hello", + `to_slug("Screenshot-https://www.nytimes.com/-2024-09-13")`: "Screenshot-https-www-nytimes-com-2024-09-13", + `to_slug(" héllo, wörld!! ")`: "héllo-wörld", `to_upper("hello")`: "HELLO", `trim("aaaHelloddd", "ad")`: "Hello", `trim_left("aaaHelloddd", "ad")`: "Helloddd",