Skip to content
Open
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ Accepts a time layout in golang [time format](http://golang.org/pkg/time/#pkg-co
<br /><br />
###### strings

**`$split(s string, separator string})`**
<br />
Return an array of strings.
<br /><br />
**`$contains(s string, substr string)`**
<br />
see [strings.Contains](http://golang.org/pkg/strings/#Contains)
Expand Down Expand Up @@ -190,4 +194,4 @@ evaluates a variable of type interface{} with a *TokenTree generated from `Parse

### changes
- **.0.1.1** addition of $bool, $~bool, $num, $str, $now, $fmtTime, $parseTime. Fix for non-alphanumeric characters in JSON keys.
- **.0.1.0** initial release
- **.0.1.0** initial release
23 changes: 23 additions & 0 deletions jee.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,26 @@ var binaryFuncs = map[string]func(interface{}, interface{}) (interface{}, error)
}
return float64(t.UnixNano() / 1000 / 1000), nil
},
"$split": func(val interface{}, b interface{}) (interface{}, error) {
sa, ok := val.(string)
if !ok {
return nil, nil
}

sb, ok := b.(string)
if !ok {
return nil, nil
}

var list []interface{}
stringList := strings.Split(sa, sb)

for _ , k := range stringList {
list = append(list, k)
}

return list, nil
},
"$fmtTime": func(a interface{}, b interface{}) (interface{}, error) {
layout, ok := a.(string)
if !ok {
Expand Down Expand Up @@ -826,6 +846,9 @@ var binaryFuncs = map[string]func(interface{}, interface{}) (interface{}, error)
if !ok {
return nil, nil
}
if b == nil {
return false, nil
}

for _, e := range s {
switch c := e.(type) {
Expand Down
12 changes: 12 additions & 0 deletions jee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,18 @@ var Tests = []Test{
exp: `$has($keys(.), "arrayString")`,
result: `true`,
},
Test{
exp: `$has($split("arrayString, arrayString2, arrayString3", ","), "arrayString")`,
result: `true`,
},
Test{
exp: `$has($split("arrayString, arrayString2, arrayString3", ","), "nope")`,
result: `false`,
},
Test{
exp: `$has($split("arrayString, arrayString2, arrayString3", ","), null)`,
result: `false`,
},
Test{
exp: `$has($keys(.), "nope")`,
result: `false`,
Expand Down