Documentation
¶
Overview ¶
Package strcase converts strings to various cases. See the conversion table below:
| Function | Result | |---------------------------------|--------------------| | ToSnake(s) | any_kind_of_string | | ToScreamingSnake(s) | ANY_KIND_OF_STRING | | ToKebab(s) | any-kind-of-string | | ToScreamingKebab(s) | ANY-KIND-OF-STRING | | ToDelimited(s, '.') | any.kind.of.string | | ToScreamingDelimited(s, '.') | ANY.KIND.OF.STRING | | ToCamel(s) | AnyKindOfString | | ToLowerCamel(s) | anyKindOfString |
Index ¶
- Constants
- func NewContext(ctx context.Context, v *Strcase) context.Context
- type Strcase
- func (ctx *Strcase) ToCamel(s string) string
- func (ctx *Strcase) ToDelimited(s string, delimiter uint8) string
- func (ctx *Strcase) ToKebab(s string) string
- func (ctx *Strcase) ToLowerCamel(s string) string
- func (ctx *Strcase) ToScreamingDelimited(s string, delimiter uint8, ignore string, screaming bool) string
- func (ctx *Strcase) ToScreamingKebab(s string) string
- func (ctx *Strcase) ToScreamingSnake(s string) string
- func (ctx *Strcase) ToSnake(s string) string
- func (ctx *Strcase) ToSnakeWithIgnore(s string, ignore string) string
Constants ¶
const ( Other byteType = iota Upper Lower Separator Digit )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Strcase ¶ added in v0.14.0
type Strcase struct {
// contains filtered or unexported fields
}
func FromContext ¶ added in v0.14.0
FromContext returns the Strcase from the given context. If not found, it will return the default Strcase.
func New ¶ added in v0.13.0
New creates a new Strcase with the given acronyms.
Examples:
- "API": "api"
- "K8s": "k8s"
- "3D": "3d"
- `A(1\d{3})`: "a$l1}"
- `(\d)[vV](\d)`: "${1}v${2}"
func (*Strcase) ToDelimited ¶ added in v0.14.0
ToDelimited converts a string to delimited.snake.case (in this case `delimiter = '.'`)
func (*Strcase) ToLowerCamel ¶ added in v0.14.0
ToLowerCamel converts a string to lowerCamelCase
func (*Strcase) ToScreamingDelimited ¶ added in v0.14.0
func (ctx *Strcase) ToScreamingDelimited(s string, delimiter uint8, ignore string, screaming bool) string
ToScreamingDelimited converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `delimiter = '.'; screaming = true`) or delimited.snake.case (in this case `delimiter = '.'; screaming = false`)
func (*Strcase) ToScreamingKebab ¶ added in v0.14.0
ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE
func (*Strcase) ToScreamingSnake ¶ added in v0.14.0
ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE