casing

package
v2.16.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package casing helps convert between CamelCase, snake_case, and others. It includes an intelligent `Split` function to take almost any input and then convert it to any type of casing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Camel

func Camel(value string, transform ...TransformFunc) string

Camel returns a CamelCase version of the input. If no transformation functions are passed in, then strings.ToLower is used. This can be disabled by passing in the identity function.

func Identity

func Identity(part string) string

Identity is the identity transformation function.

func Initialism

func Initialism(part string) string

Initialism converts common initialisms like ID and HTTP to uppercase.

func Join

func Join(parts []string, sep string, transform ...TransformFunc) string

Join will combine split parts back together with the given separator and optional transform functions.

func Kebab

func Kebab(value string, transform ...TransformFunc) string

Kebab returns a kabob-case version of the input.

func LowerCamel

func LowerCamel(value string, transform ...TransformFunc) string

LowerCamel returns a lowerCamelCase version of the input.

func MergeNumbers

func MergeNumbers(parts []string, suffixes ...string) []string

MergeNumbers will merge some number parts with their adjacent letter parts to support a smarter delimited join. For example, `h264` instead of `h_264` or `mp3-player` instead of `mp-3-player`. You can pass suffixes for right aligning certain items, e.g. `K` to get `MODE_4K` instead of `MODE4_K`. If no suffixes are passed, then a default set of common ones is used. Pass an empty string to disable the default.

func Snake

func Snake(value string, transform ...TransformFunc) string

Snake returns a snake_case version of the input.

func Split

func Split(value string) []string

Split a value intelligently, taking into account different casing styles, numbers, symbols, etc.

// Returns: ["HTTP", "Server", "2020"]
casing.Split("HTTPServer_2020")

Types

type TransformFunc

type TransformFunc func(string) string

TransformFunc is used to transform parts of a split string during joining.

Jump to

Keyboard shortcuts

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