Documentation ¶
Overview ¶
Package stringfy is a simple string manipulation for Go.
Example of usage:
package main import ( "fmt" "github.com/hgsigner/stringfy" ) func main() { es := stringfy.Escape("São Paulo") fmt.Prinln(es) // Sao Paulo cc := stringfy.CamelCase("fizz_buzz_bazz") fmt.Prinln(cc) // FizzBuzzBazz un := stringfy.Parameterize("São Paulo") fmt.Prinln(un) // sao-paulo un := stringfy.Underscore("São Paulo") fmt.Prinln(un) // sao_paulo p := stringfy.NewPlural() p.Perform(2, "octopus") fmt.Println(p) // 2 octopi }
Index ¶
- func CamelCase(st string) string
- func Escape(s string) string
- func Parameterize(s string) string
- func Underscore(s string) string
- type Excerpter
- type LengthOption
- type LineWidthOption
- type OmissionOption
- type OptPlural
- type PluralSet
- type RadiusOption
- type SeparatorOption
- type Truncater
- type WordWraper
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Escape ¶
Escape special characters from a text. Reads through the rules' table and mateches if a given character is present in the passed string. If so, it will replace it.
func Parameterize ¶
Parameterize performs parameterization on a string.
Types ¶
type Excerpter ¶
type Excerpter struct {
// contains filtered or unexported fields
}
Excerpter struct
func NewExcerpt ¶
func NewExcerpt() *Excerpter
NewExcerpt creates a new instace of the Excerpter struct with its defaults.
type LengthOption ¶
type LengthOption func(lengther)
LengthOption is a function that accepts interface lengther
type LineWidthOption ¶
type LineWidthOption func(lineWidther)
LineWidthOption is a function that accepts interface lineWidther
type OmissionOption ¶
type OmissionOption func(omissioner)
OmissionOption function that accepts interface omissioner
type PluralSet ¶
type PluralSet struct {
// contains filtered or unexported fields
}
PluralSet struct
func NewPlural ¶
func NewPlural() *PluralSet
NewPlural initializes the PluralSet struct
Example ¶
package main import ( "fmt" "github.com/hgsigner/stringfy" ) func main() { p1 := stringfy.NewPlural() fmt.Println(p1.Perform(2, "octopus")) p2 := stringfy.NewPlural() fmt.Println(p2.Perform(2, "post")) p3 := stringfy.NewPlural() fmt.Println(p3.Perform(2, "jeans")) //Custom plural pc := stringfy.NewPlural() pc.Options(stringfy.AddPlural("boatys")) fmt.Println(pc.Perform(2, "boat")) }
Output: 2 octopi 2 posts 2 jeans 2 boatys
type RadiusOption ¶
type RadiusOption func(radiuser)
RadiusOption is a function that accepts interface radiuser
type SeparatorOption ¶
type SeparatorOption func(separatorer)
SeparatorOption is a function that accepts interface separatorer
func AddSeparator ¶
func AddSeparator(sep string) SeparatorOption
AddSeparator adds a custom separator
type Truncater ¶
type Truncater struct {
// contains filtered or unexported fields
}
Truncater struct
func NewTruncate ¶
func NewTruncate() *Truncater
NewTruncate creates a new instance of the Truncater struct if its defaults.
type WordWraper ¶
type WordWraper struct {
// contains filtered or unexported fields
}
WordWraper struct
func NewWordWrap ¶
func NewWordWrap() *WordWraper
NewWordWrap creates a new instance of the WordWraper struct if its defaults.
func (*WordWraper) Options ¶
func (wwr *WordWraper) Options(options ...interface{})
Options sets LineWidthOption
func (*WordWraper) Perform ¶
func (wwr *WordWraper) Perform(text string) string
Perform the wraping of a given text.