forked from diegoholiveira/jsonlogic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp.go
More file actions
46 lines (35 loc) · 706 Bytes
/
comp.go
File metadata and controls
46 lines (35 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package jsonlogic
import (
"reflect"
)
func less(a, b interface{}) bool {
// comparison to a nil value is falsy
if a == nil || b == nil {
return false
}
if isNumber(a) || isNumber(b) {
return toNumber(b) > toNumber(a)
}
return toString(b) > toString(a)
}
func hardEquals(a, b interface{}) bool {
ra := reflect.ValueOf(a).Kind()
rb := reflect.ValueOf(b).Kind()
if ra != rb {
return false
}
return equals(a, b)
}
func equals(a, b interface{}) bool {
// comparison to a nil value is falsy
if a == nil || b == nil {
return false
}
if isNumber(a) {
return toNumber(a) == toNumber(b)
}
if isBool(a) {
return isTrue(a) == isTrue(b)
}
return toString(a) == toString(b)
}