Documentation ΒΆ
Index ΒΆ
- Variables
- func Align(str string, opts *AlignOptions) string
- func AlignCenter(str string) string
- func AlignLeft(str string) string
- func AlignRight(str string) string
- func Capitalize(s string) string
- func Dedent(s string, level int) string
- func DetermineIndentation(lines ...string) (min, max int)
- func DetermineWidths(array [][]string) []int
- func HereDoc(s string) string
- func HereDocf(format string, args ...any) string
- func IsCase(s string, c Case) bool
- func IsSpace(r rune) bool
- func Pad(s, char string, count int) string
- func PadLeft(s, char string, count int) string
- func PadRight(s, char string, count int) string
- func ToCamelCase(s string) string
- func ToCase(s string, c Case) string
- func ToKebabCase(s string) string
- func ToSnakeCase(s string) string
- func ToTitleCase(s string) string
- func Uncapitalize(s string) string
- type AlignOptions
- type Case
- type StringAndWidthTuple
Examples ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
var CaseRegex = map[Case]*regexp.Regexp{ CamelCase: regexp.MustCompile(`^[a-z][a-zA-Z0-9]+(?:[A-Z][a-z0-9]+)*$`), SnakeCase: regexp.MustCompile(`^[a-z][a-zA-Z0-9]+(?:[_][a-z][a-z0-9]+)*$`), KebabCase: regexp.MustCompile(`^[a-z][a-zA-Z0-9]+(?:[-][a-z][a-z0-9]+)*$`), TitleCase: regexp.MustCompile(`^[A-Z][a-zA-Z0-9]+(?:[A-Z][a-zA-Z0-9]+)*$`), }
Functions ΒΆ
func Align ΒΆ
func Align(str string, opts *AlignOptions) string
func Capitalize ΒΆ
Capitalize the string (make the first letter uppercase)
func Dedent ΒΆ
Dedent removes leading spaces and tabs from each line of the given string up to the specified level.
func DetermineIndentation ΒΆ
Determines the minimum and maximum level of indentation for the given lines. The lines can be passed as a slice of strings or as a single multi-line string.
func DetermineWidths ΒΆ
Determines the width of each column in a 2D array of strings
func HereDoc ΒΆ
HereDoc returns a here-document representation of the given string. See https://en.m.wikipedia.org/wiki/Here_document for more information.
Example (Multiline) ΒΆ
Multiline example
// Print a here-document fmt.Println(HereDoc(` Hello, World! `))
Output: Hello, World!
Example (Simple) ΒΆ
Simple example
// Print a here-document fmt.Println(HereDoc(` Hello, World! `))
Output: Hello, World!
func HereDocf ΒΆ
HereDocf returns a here-document (https://en.m.wikipedia.org/wiki/Here_document) representation of the given string. The can be formatted using the given arguments as in fmt.Sprintf.
Example (Multiline) ΒΆ
Multiline example
// Print a here-document fmt.Println(HereDocf(` %s, %s! `, "Hello", "World"))
Output: Hello, World!
Example (Simple) ΒΆ
Simple example
// Print a here-document fmt.Println(HereDocf(` %s `, "Hello, World!"))
Output: Hello, World!
func Pad ΒΆ
Apply padding around the string
Example ΒΆ
str := "Golang" newStr := Pad(str, "|", 2) fmt.Println(newStr)
Output: ||Golang||
func PadLeft ΒΆ
Apply padding to the left of the string
Example ΒΆ
str := "Golang" newStr := PadLeft(str, ">>", 1) fmt.Println(newStr)
Output: >>Golang
func PadRight ΒΆ
Apply padding to the right of the string
Example ΒΆ
str := "Golang" newStr := PadRight(str, ">", 3) fmt.Println(newStr)
Output: Golang>>>
func Uncapitalize ΒΆ
Uncapitalize the string (make the first letter lowercase)
Types ΒΆ
type AlignOptions ΒΆ
func (*AlignOptions) AssignValues ΒΆ
func (opts *AlignOptions) AssignValues()
AssignValues assigns default values to the options
type Case ΒΆ
type Case int
func DetermineCase ΒΆ
DetermineCase returns the case of the string or -1 if it is not a known case
type StringAndWidthTuple ΒΆ
type StringAndWidthTuple struct {
// contains filtered or unexported fields
}