1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-02 14:27:46 +01:00
liquid/values/predicates.go

23 lines
439 B
Go
Raw Normal View History

2017-07-28 00:11:37 +02:00
package values
2017-07-06 01:09:59 +02:00
import (
"reflect"
)
2017-07-06 01:09:59 +02:00
// IsEmpty returns a bool indicating whether the value is empty according to Liquid semantics.
func IsEmpty(value interface{}) bool {
value = ToLiquid(value)
if value == nil {
return false
}
r := reflect.ValueOf(value)
switch r.Kind() {
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
return r.Len() == 0
case reflect.Bool:
return !r.Bool()
default:
return false
}
}