Documentation ¶
Overview ¶
Package varcaser provides a way to change the case of variable names.
result := Caser{From: LowerCamelCase, To: KebabCase}.String("someInitMethod") // "some-init-method" result := Caser{From: LowerCamelCase, To: ScreamingSnakeCase}.String("myConstantVariable") // "MY_CONSTANT_VARIABLE"
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInconsistentData = fmt.Errorf("Inconsistent data provided.")
ErrInconsistentData is returned when the input data contradicts itself. In this case, no useful information is returned from Detect().
var ErrNoData = fmt.Errorf("No data provided.")
ErrNoData is returned when an empty or nil slice is passed in. In this case, no useful information is returned from Detect().
var ErrNotEnoughData = fmt.Errorf("Not enough data provided.")
ErrNotEnoughData is returned when an accurate determination could not be made. However, the best guess will be provided in the returned CaseConvention.
var HttpAcronyms = map[string]bool{ "XSS": true, "SSL": true, "HTTP": true, "MD5": true, "TE": true, "DNT": true, "UIDH": true, "P3P": true, "WWW": true, "CSP": true, "UA": true, }
HttpAcronyms is effectively a set of acronyms that are conventionally uppercased in the HTTP Casing Convention.
var HttpHeaderCase = CaseConvention{ JoinStyle: SimpleJoinStyle("-"), InitialCase: ToHttpTitle, SubsequentCase: ToHttpTitle, Example: "HTTP-Header-Case", }
var KebabCase = CaseConvention{ JoinStyle: SimpleJoinStyle("-"), InitialCase: strings.ToLower, SubsequentCase: strings.ToLower, Example: "kebab-case", }
var LowerCamelCase = CaseConvention{ JoinStyle: camelJoinStyle, InitialCase: strings.ToLower, SubsequentCase: ToStrictTitle, Example: "lowerCamelCase", }
var LowerCamelCaseKeepCaps = CaseConvention{ JoinStyle: camelJoinStyle, InitialCase: strings.ToLower, SubsequentCase: strings.Title, Example: "lowerCamelCase", }
var LowerSnakeCase = CaseConvention{ JoinStyle: SimpleJoinStyle("_"), InitialCase: strings.ToLower, SubsequentCase: strings.ToLower, Example: "lower_snake_case", }
var ScreamingKebabCase = CaseConvention{ JoinStyle: SimpleJoinStyle("-"), InitialCase: strings.ToUpper, SubsequentCase: strings.ToUpper, Example: "SCREAMING-KEBAB-CASE", }
var ScreamingSnakeCase = CaseConvention{ JoinStyle: SimpleJoinStyle("_"), InitialCase: strings.ToUpper, SubsequentCase: strings.ToUpper, Example: "SCREAMING_SNAKE_CASE", }
var UpperCamelCase = CaseConvention{ JoinStyle: camelJoinStyle, InitialCase: ToStrictTitle, SubsequentCase: ToStrictTitle, Example: "UpperCamelCase", }
var UpperCamelCaseKeepCaps = CaseConvention{ JoinStyle: camelJoinStyle, InitialCase: strings.Title, SubsequentCase: strings.Title, Example: "UpperCamelCase", }
var UpperKebabCase = CaseConvention{ JoinStyle: SimpleJoinStyle("-"), InitialCase: ToStrictTitle, SubsequentCase: ToStrictTitle, Example: "Upper-Kebab-Case", }
Functions ¶
func ToHttpTitle ¶
ToHttpTitle returns a string titled the way HTTP Headers title it.
func ToStrictTitle ¶
ToStrictTitle returns the strict titling of a string without preserving existing caps in acronyms.
Types ¶
type CaseConvention ¶
type CaseConvention struct { JoinStyle SubsequentCase WordCase InitialCase WordCase Example string // Render the name of this case convention in itself }
A CaseConvention is a way of writing variable names using separators and casing style.
func (CaseConvention) SplitWords ¶
func (c CaseConvention) SplitWords(s string) []string
SplitWords allows CaseConvention to implement Splitter.
type Caser ¶
type Caser struct { From Splitter To CaseConvention transform.NopResetter }
type Caser is a text transformer that takes converts a variable from one casing convention to another.
func (Caser) Bytes ¶
Bytes is provided for compatibility with the Transformer interface. Since Caser has no special treatment of bytes, the bytes are converted to and from strings.
func (Caser) String ¶
String returns the representation of a variable name in this Caser's To CaseConvention given a variable name in this Caser's From CaseConvention.
type Detected ¶
func (Detected) SplitWords ¶
type JoinStyle ¶
A JoinStyle is a way of representing how individual components of a variable name are put together, and how to pull them apart.
func SimpleJoinStyle ¶
SimpleJoinStyle creates a JoinStyle that just splits and joins by a separator.