File: format.go

package info (click to toggle)
golang-github-nicholas-fedor-shoutrrr 0.8.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,332 kB
  • sloc: sh: 61; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 723 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package format

import (
	"strconv"
	"strings"
)

// ParseBool returns true for "1","true","yes" or false for "0","false","no" or defaultValue for any other value.
func ParseBool(value string, defaultValue bool) (bool, bool) {
	switch strings.ToLower(value) {
	case "true", "1", "yes", "y":
		return true, true
	case "false", "0", "no", "n":
		return false, true
	default:
		return defaultValue, false
	}
}

// PrintBool returns "Yes" if value is true, otherwise returns "No".
func PrintBool(value bool) string {
	if value {
		return "Yes"
	}

	return "No"
}

// IsNumber returns whether the specified string is number-like.
func IsNumber(value string) bool {
	_, err := strconv.ParseFloat(value, 64)

	return err == nil
}