Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mingrammer/tyfy

Truthy and falsy text validators
https://github.com/mingrammer/tyfy

falsy truthy validator

Last synced: about 2 months ago
JSON representation

Truthy and falsy text validators

Awesome Lists containing this project

README

        



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](https://godoc.org/github.com/mingrammer/tyfy)

```go
IsTruthy("yes")
IsTruthy("no")
// true
// false

IsFalsy("n")
IsFalsy("y")
// true
// false
```

You can extend the set of values as needed.

```go
ExtendTruthy([]string{"o"})
ExtendFalsy([]string{"x"})
```

## License

MIT