Documentation
¶
Overview ¶
Package casing is the single definition of the naming conventions that the casing rules enforce: the Casing enum, its parser, one implementation of "does this name follow that convention" and a converter that proposes the correctly cased name.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Casing ¶
type Casing string
Casing is a naming convention.
const ( // Kebab is lower case words joined by hyphens: pet-owner. Kebab Casing = "kebab-case" // Snake is lower case words joined by underscores: pet_owner. Snake Casing = "snake_case" // Camel is lowerCamelCase: petOwner. Camel Casing = "camelCase" // Pascal is UpperCamelCase: PetOwner. Pascal Casing = "PascalCase" // ScreamingSnake is upper case words joined by underscores: PET_OWNER. ScreamingSnake Casing = "SCREAMING_SNAKE_CASE" // ScreamingKebab is upper case words joined by hyphens: PET-OWNER. ScreamingKebab Casing = "SCREAMING-KEBAB-CASE" // Dot is lower case words joined by dots: pet.owner. Dot Casing = "dot.case" // Lower is lower case letters and digits only, with no separator: petowner. Lower Casing = "lowercase" )
func Parse ¶
Parse converts an option value into a Casing. An unknown value is an UnknownError rather than a silent fallback.
func (Casing) Append ¶ added in v1.15.0
Append adds word to the end of name as a new word of the convention.
func (Casing) Convert ¶
Convert rewrites name in the convention. Words are found at separators (hyphen, underscore, dot, space) and at lower-to-upper case changes. Acronyms such as ID are kept intact in the camel conventions.
func (Casing) HasWordPrefix ¶ added in v1.15.0
HasWordPrefix reports whether name starts with word as its first word in the convention. The word is matched as given, except in the capitalised conventions. In the separated conventions the separator must follow it, in the camel conventions an upper-case letter and in lowercase any character.
type Set ¶
type Set []Casing
Set is the list of conventions a name may follow; a name is valid when it follows any one of them.
func (Set) Append ¶ added in v1.15.0
Append adds word to the end of name as a new word of the first convention of the set. An empty set leaves the name alone.
type UnknownError ¶
type UnknownError struct {
// Value is the rejected value.
Value string
}
UnknownError reports a value that names no casing.
func (UnknownError) Error ¶
func (e UnknownError) Error() string
Error implements error and names every allowed value.