Documentation ¶
Overview ¶
Package strnaming is used to replace the naming method of strings.
For example:
package main import ( "fmt" "github.com/startdusk/strnaming" ) func main() { // camel camel := strnaming.NewCamel() fmt.Println(camel.Convert("camelcase_key")) // camelcaseKey }
set preifx
camel.WithPrefix("My") fmt.Println(camel.Convert("user_id")) // MyuserId
set first char upper
fmt.Println(camel.Convert("user_id")) // userId camel.WithUpperFirst(true) fmt.Println(camel.Convert("user_id")) // UserId
set prefix
camel.WithPrefix("My") fmt.Println(camel.Convert("user_name")) // MyuserName
set customize delimiter
camel.WithDelimiter('-') fmt.Println(camel.Convert("user-id")) // userId
set cache
camel.WithCache("user_id", "UserID") fmt.Println(camel.Convert("user_id")) // UserID
set style
package main import ( "fmt" "github.com/startdusk/strnaming" "github.com/startdusk/strnaming/style" ) func main() { // camel camel := strnaming.NewCamel() camel.WithStyle(style.NewGolang()) fmt.Println(camel.Convert("http_test")) // HTTPTest fmt.Println(camel.Convert("json_data")) // JSONData }
Index ¶
- type Camel
- func (c *Camel) Convert(str string) string
- func (c *Camel) WithCache(key, value string) *Camel
- func (c *Camel) WithDelimiter(delimiters ...byte) *Camel
- func (c *Camel) WithPrefix(prefix string) *Camel
- func (c *Camel) WithStyle(style Style) *Camel
- func (c *Camel) WithUpperFirst(upperFirst bool) *Camel
- type Spacer
- type Style
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Camel ¶
type Camel struct {
// contains filtered or unexported fields
}
Camel defines a cameler
func (*Camel) WithDelimiter ¶ added in v0.2.0
WithDelimiter set delimiter char
func (*Camel) WithPrefix ¶ added in v0.2.0
WithPrefix set prefix
func (*Camel) WithUpperFirst ¶ added in v0.4.0
WithUpperFirst set first char upper
type Spacer ¶
type Spacer struct {
// contains filtered or unexported fields
}
Spacer defines a spacer struct
func (*Spacer) WithIgnore ¶
WithIgnore ignore special char eg $
func (*Spacer) WithPrefix ¶ added in v0.2.0
WithPrefix set prefix
func (*Spacer) WithScreaming ¶
WithScreaming convert all char for upper
Click to show internal directories.
Click to hide internal directories.