Truthy and falsy text validators
A truthy value is a value that is considered true, and a falsy value is a value that is considered false.
tyfy (short of "truthy and falsy") provides two simple validators for the truthy and falsy text values (string only). It is useful for some programs that accept the human-readable true/false value as input from users, for example, the command line tools with a prompt such as (y/n)
.
The default values of the truthy and falsy are "1", "true", "t", "yes", "y", "ok"
and "0", "false", "f", "no", "n"
, respectively.
go get github.com/mingrammer/tyfy
See details in GoDoc
IsTruthy("yes")
IsTruthy("no")
// true
// false
IsFalsy("n")
IsFalsy("y")
// true
// false
You can extend the set of values as needed.
ExtendTruthy([]string{"o"})
ExtendFalsy([]string{"x"})
MIT