mingrammer / tyfy

Truthy and falsy text validators

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool



TyFy

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.

Installation

go get github.com/mingrammer/tyfy

Usage

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"})

License

MIT

About

Truthy and falsy text validators

License:MIT License


Languages

Language:Go 100.0%