forked from TomWright/dasel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
truthy.go
61 lines (51 loc) · 838 Bytes
/
truthy.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package dasel
import (
"reflect"
"strings"
)
func IsTruthy(value interface{}) bool {
switch v := value.(type) {
case Value:
return IsTruthy(v.Unpack().Interface())
case reflect.Value:
return IsTruthy(unpackReflectValue(v).Interface())
case bool:
return v
case string:
v = strings.ToLower(strings.TrimSpace(v))
switch v {
case "false", "no", "0":
return false
default:
return v != ""
}
case []byte:
return IsTruthy(string(v))
case int:
return v > 0
case int8:
return v > 0
case int16:
return v > 0
case int32:
return v > 0
case int64:
return v > 0
case uint:
return v > 0
case uint8:
return v > 0
case uint16:
return v > 0
case uint32:
return v > 0
case uint64:
return v > 0
case float32:
return v >= 1
case float64:
return v >= 1
default:
return false
}
}