strcase

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 2 Imported by: 20

README

go-strcase

Convert between string case styles

Doc

strcase - GoDoc

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var CommonInitialisms = map[string]bool{
	"acl":   true,
	"api":   true,
	"ascii": true,
	"cpu":   true,
	"css":   true,
	"dns":   true,
	"eof":   true,
	"guid":  true,
	"html":  true,
	"http":  true,
	"https": true,
	"id":    true,
	"ip":    true,
	"json":  true,
	"lhs":   true,
	"qps":   true,
	"ram":   true,
	"rhs":   true,
	"rpc":   true,
	"sla":   true,
	"smtp":  true,
	"sql":   true,
	"ssh":   true,
	"tcp":   true,
	"tls":   true,
	"ttl":   true,
	"udp":   true,
	"ui":    true,
	"uid":   true,
	"uuid":  true,
	"uri":   true,
	"url":   true,
	"utf8":  true,
	"vm":    true,
	"xml":   true,
	"xmpp":  true,
	"xsrf":  true,
	"xss":   true,
}

CommonInitialisms is a set of common initialisms. Copy from https://github.com/golang/lint `commonInitialisms`.

Functions

func SplitIntoWords

func SplitIntoWords(s string) []string

SplitIntoWords splits string to words.

func SplitIntoWordsWithInitialisms added in v1.0.1

func SplitIntoWordsWithInitialisms(s string, initialisms map[string]bool) []string

SplitIntoWordsWithInitialisms splits string to words with initialisms.

func ToLowerCamel

func ToLowerCamel(s string) string

ToLowerCamel convert string to lowerCamel.

Example
fmt.Println(strcase.ToLowerCamel("lowerCamel"))
fmt.Println(strcase.ToLowerCamel("UpperCamel"))
fmt.Println(strcase.ToLowerCamel("lower_snake"))
fmt.Println(strcase.ToLowerCamel("UPPER_SNAKE"))
Output:

lowerCamel
upperCamel
lowerSnake
upperSnake

func ToLowerCamelWithInitialisms added in v1.0.1

func ToLowerCamelWithInitialisms(s string, initialisms map[string]bool) string

ToLowerCamelWithInitialisms convert string to lowerCamel with initialisms.

func ToLowerSnake

func ToLowerSnake(s string) string

ToLowerSnake convert string to lower_snake.

Example
fmt.Println(strcase.ToLowerSnake("lowerCamel"))
fmt.Println(strcase.ToLowerSnake("UpperCamel"))
fmt.Println(strcase.ToLowerSnake("lower_snake"))
fmt.Println(strcase.ToLowerSnake("UPPER_SNAKE"))
Output:

lower_camel
upper_camel
lower_snake
upper_snake

func ToUpperCamel

func ToUpperCamel(s string) string

ToUpperCamel convert string to UpperCamel.

Example
fmt.Println(strcase.ToUpperCamel("lowerCamel"))
fmt.Println(strcase.ToUpperCamel("UpperCamel"))
fmt.Println(strcase.ToUpperCamel("lower_snake"))
fmt.Println(strcase.ToUpperCamel("UPPER_SNAKE"))
Output:

LowerCamel
UpperCamel
LowerSnake
UpperSnake

func ToUpperCamelWithInitialisms added in v1.0.1

func ToUpperCamelWithInitialisms(s string, initialisms map[string]bool) string

ToUpperCamelWithInitialisms convert string to UpperCamel with initialisms.

func ToUpperSnake

func ToUpperSnake(s string) string

ToUpperSnake convert string to UPPER_SNAKE.

Example
fmt.Println(strcase.ToUpperSnake("lowerCamel"))
fmt.Println(strcase.ToUpperSnake("UpperCamel"))
fmt.Println(strcase.ToUpperSnake("lower_snake"))
fmt.Println(strcase.ToUpperSnake("UPPER_SNAKE"))
Output:

LOWER_CAMEL
UPPER_CAMEL
LOWER_SNAKE
UPPER_SNAKE

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL