Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -131,6 +131,7 @@ func main() {
| to_bool(input interface{}) bool | Converts the input to a boolean value | `to_bool("true")`<br>`to_bool(1)`<br>`to_bool("")` | `true`<br>`true`<br>`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")`<br>`to_unix_time("2022-01-13 16:30:10")`<br>`to_unix_time("13-01-2022 16:30:10". "02-01-2006 15:04:05")` | `1642091410` |
Expand All @@ -143,7 +144,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<br>uniq(input number) string<br>uniq(elements ...interface{}) []interface{} | Removes duplicate characters from a string, digits from a number, or elements from a list | `uniq("aabbcc")`<br>`uniq(112233)`<br>`uniq("b", "a", "b")` | `abc`<br>`123`<br>`["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")`<br>`url_encode("test@example.com", true)` | `https%3A%2F%2Fprojectdiscovery.io%2Ftest%3Fa%3D1`<br>`test%40example%2Ecom` |
| wait_for(seconds uint) | Pauses the execution for the given amount of seconds | `wait_for(10)` | `true` |
Expand Down Expand Up @@ -174,7 +175,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

Expand Down
7 changes: 7 additions & 0 deletions dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"strconv"
"strings"
"time"
"unicode"

"github.com/Mzack9999/gcache"
"github.com/asaskevich/govalidator"
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions dsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Loading