Documentation ¶
Overview ¶
Package strcase provides functions for manipulating the case of strings (CamelCase, kebab-case, snake_case, Sentence case, etc). It is based on https://github.com/ettle/strcase, which is Copyright (c) 2020 Liyan David Chang under the MIT License. Its principle difference from other strcase packages is that it preserves acronyms in input text for CamelCase. Therefore, you must call strings.ToLower on any SCREAMING_INPUT_STRINGS before passing them to ToCamel, ToLowerCamel, ToTitle, and ToSentence.
Index ¶
- func FormatList(items ...string) string
- func To(s string, c Cases) string
- func ToCamel(s string) string
- func ToKEBAB(s string) string
- func ToKebab(s string) string
- func ToLowerCamel(s string) string
- func ToSNAKE(s string) string
- func ToSentence(s string) string
- func ToSnake(s string) string
- func ToTitle(s string) string
- func ToWordCase(input string, wordCase WordCases, delimiter rune) string
- type Cases
- type SplitAction
- type WordCases
- func (i WordCases) Desc() string
- func (i WordCases) Int64() int64
- func (i WordCases) MarshalText() ([]byte, error)
- func (i *WordCases) SetInt64(in int64)
- func (i *WordCases) SetString(s string) error
- func (i WordCases) String() string
- func (i *WordCases) UnmarshalText(text []byte) error
- func (i WordCases) Values() []enums.Enum
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatList ¶
FormatList returns a formatted version of the given list of items following these rules:
- nil => ""
- "Go" => "Go"
- "Go", "Python" => "Go and Python"
- "Go", "Python", "JavaScript" => "Go, Python, and JavaScript"
- "Go", "Python", "JavaScript", "C" => "Go, Python, JavaScript, and C"
func ToCamel ¶
ToCamel returns words in CamelCase (capitalized words concatenated together). Also known as UpperCamelCase.
func ToKEBAB ¶
ToKEBAB returns words in KEBAB-CASE (upper case words with dashes). Also known as SCREAMING-KEBAB-CASE or SCREAMING-DASH-CASE.
func ToKebab ¶
ToKebab returns words in kebab-case (lower case words with dashes). Also known as dash-case.
func ToLowerCamel ¶
ToLowerCamel returns words in lowerCamelCase (capitalized words concatenated together, with first word lower case). Also known as camelCase or mixedCase.
func ToSNAKE ¶
ToSNAKE returns words in SNAKE_CASE (upper case words with underscores). Also known as SCREAMING_SNAKE_CASE or UPPER_CASE.
func ToSentence ¶
ToSentence returns words in Sentence case (lower case words with spaces, with the first word capitalized).
Types ¶
type Cases ¶
type Cases int32 //enums:enum
Cases is an enum with all of the different string cases.
const ( // LowerCase is all lower case LowerCase Cases = iota // UpperCase is all UPPER CASE UpperCase // SnakeCase is lower_case_words_with_underscores SnakeCase // SNAKECase is UPPER_CASE_WORDS_WITH_UNDERSCORES SNAKECase // KebabCase is lower-case-words-with-dashes KebabCase // KEBABCase is UPPER-CASE-WORDS-WITH-DASHES KEBABCase // CamelCase is CapitalizedWordsConcatenatedTogether CamelCase // LowerCamelCase is capitalizedWordsConcatenatedTogether, with the first word lower case LowerCamelCase // TitleCase is Captitalized Words With Spaces TitleCase // SentenceCase is Lower case words with spaces, with the first word capitalized SentenceCase )
const CasesN Cases = 10
CasesN is the highest valid value for type Cases, plus one.
func CasesValues ¶
func CasesValues() []Cases
CasesValues returns all possible values for the type Cases.
func (Cases) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Cases) SetString ¶
SetString sets the Cases value from its string representation, and returns an error if the string is invalid.
func (*Cases) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type SplitAction ¶
type SplitAction int
SplitAction defines if and how to split a string
const ( // Noop - Continue to next character Noop SplitAction = iota // Split - Split between words // e.g. to split between wordsWithoutDelimiters Split // SkipSplit - Split the word and drop the character // e.g. to split words with delimiters SkipSplit // Skip - Remove the character completely Skip )
type WordCases ¶
type WordCases int32 //enums:enum -trim-prefix Word
WordCases is an enumeration of the ways to format a word.
const ( // WordOriginal indicates to preserve the original input case. WordOriginal WordCases = iota // WordLowerCase indicates to make all letters lower case (example). WordLowerCase // WordUpperCase indicates to make all letters upper case (EXAMPLE). WordUpperCase // WordTitleCase indicates to make only the first letter upper case (Example). WordTitleCase // WordCamelCase indicates to make only the first letter upper case, except // in the first word, in which all letters are lower case (exampleText). WordCamelCase // WordSentenceCase indicates to make only the first letter upper case, and // only for the first word (all other words have fully lower case letters). WordSentenceCase )
const WordCasesN WordCases = 6
WordCasesN is the highest valid value for type WordCases, plus one.
func WordCasesValues ¶
func WordCasesValues() []WordCases
WordCasesValues returns all possible values for the type WordCases.
func (WordCases) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*WordCases) SetString ¶
SetString sets the WordCases value from its string representation, and returns an error if the string is invalid.
func (*WordCases) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.