Skip to content

Commit

Permalink
feat: add jp functions docs
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly committed Sep 27, 2024
1 parent 790f57d commit 2cf0a80
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 1,289 deletions.
4 changes: 2 additions & 2 deletions pkg/jp/functions/at.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
func jpfAt(arguments []any) (any, error) {
if slice, ok := arguments[0].([]any); !ok {
return nil, errors.New("invalid type, first argument must be an array")
} else if index, ok := arguments[1].(int); !ok {
} else if index, ok := arguments[1].(float64); !ok {
return nil, errors.New("invalid type, second argument must be an int")
} else {
return slice[index], nil
return slice[int(index)], nil
}
}
15 changes: 9 additions & 6 deletions pkg/jp/functions/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@ func GetFunctions() []functions.FunctionEntry {
Name: "at",
Arguments: []functions.ArgSpec{
{Types: []functions.JpType{functions.JpArray}},
// TODO: we should introduce a JpInteger type
{Types: []functions.JpType{functions.JpAny}},
{Types: []functions.JpType{functions.JpNumber}},
},
Handler: jpfAt,
Handler: jpfAt,
Description: "Returns the element in an array at the given index.",
}, {
Name: "concat",
Arguments: []functions.ArgSpec{
{Types: []functions.JpType{functions.JpString}},
{Types: []functions.JpType{functions.JpString}},
},
Handler: jpfConcat,
Handler: jpfConcat,
Description: "Concatenates two strings together and returns the result.",
}, {
Name: "json_parse",
Arguments: []functions.ArgSpec{
{Types: []functions.JpType{functions.JpString}},
},
Handler: jpfJsonParse,
Handler: jpfJsonParse,
Description: "Parses a given JSON string into an object.",
}, {
Name: "wildcard",
Arguments: []functions.ArgSpec{
{Types: []functions.JpType{functions.JpString}},
{Types: []functions.JpType{functions.JpString}},
},
Handler: jpfWildcard,
Handler: jpfWildcard,
Description: "Compares a wildcard pattern with a given string and returns if they match or not.",
}}
}
Loading

0 comments on commit 2cf0a80

Please sign in to comment.