github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/types/to_boolean.go (about) 1 package types 2 3 import ( 4 "context" 5 6 "github.com/MontFerret/ferret/pkg/runtime/core" 7 "github.com/MontFerret/ferret/pkg/runtime/values" 8 ) 9 10 // TO_BOOL takes an input value of any type and converts it into the appropriate boolean value. 11 // None is converted to false 12 // Numbers are converted to true, except for 0, which is converted to false 13 // Strings are converted to true if they are non-empty, and to false otherwise 14 // Dates are converted to true if they are not zero, and to false otherwise 15 // Arrays are always converted to true (even if empty) 16 // Objects / HtmlNodes / Binary are always converted to true 17 // @param {Any} value - Input value of arbitrary type. 18 // @return {Boolean} - The appropriate boolean value. 19 func ToBool(_ context.Context, args ...core.Value) (core.Value, error) { 20 err := core.ValidateArgs(args, 1, 1) 21 22 if err != nil { 23 return values.None, err 24 } 25 26 return values.ToBoolean(args[0]), nil 27 }