casing

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Names

func Names() []string

Names returns the accepted option values, one per casing.

func Words

func Words(name string) []string

Words splits name into words at separators and at case changes.

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 All

func All() []Casing

All returns every supported casing.

func Parse

func Parse(value string) (Casing, error)

Parse converts an option value into a Casing. An unknown value is an UnknownError rather than a silent fallback.

func (Casing) Convert

func (c Casing) Convert(name string) string

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) Matches

func (c Casing) Matches(name string) bool

Matches reports whether name follows the convention. Only ASCII letters and digits are word characters, so any other character makes the name invalid.

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 ParseSet

func ParseSet(values []string) (Set, error)

ParseSet converts option values into a Set, failing on the first unknown one.

func (Set) Convert

func (s Set) Convert(name string) string

Convert rewrites name in the first convention of the set.

func (Set) Matches

func (s Set) Matches(name string) bool

Matches reports whether name follows at least one convention of the set. An empty set accepts every name.

func (Set) String

func (s Set) String() string

String lists the conventions for a message: "snake_case or PascalCase".

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.

Jump to

Keyboard shortcuts

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