casbab

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: BSD-3-Clause Imports: 2 Imported by: 8

README

Camel Snake Kebab

CLI tool and a Go library for converting representation style of compound words or phrases.

GoDoc

Installation

go get resenje.org/casbab/cmd/casbab
docker pull janos/casbab

Example usage

casbab screaming-snake "Camel Snake Kebab"
env | cut -d= -f1 | casbab kebab
docker run --rm janos/casbab screaming-snake "Camel Snake Kebab"
env | cut -d= -f1 | docker run --rm -i janos/casbab kebab

Performance

Benchmarks run on MacBook Pro M1Pro yield these timings:

goos: darwin
goarch: arm64
pkg: resenje.org/casbab
BenchmarkCamel
BenchmarkCamel-10               3493452        336.7 ns/op      208 B/op        2 allocs/op
BenchmarkPascal
BenchmarkPascal-10              3532380        340.4 ns/op      208 B/op        2 allocs/op
BenchmarkSnake
BenchmarkSnake-10               3257454        366.4 ns/op      288 B/op        3 allocs/op
BenchmarkCamelSnake
BenchmarkCamelSnake-10          3164365        378.6 ns/op      288 B/op        3 allocs/op
BenchmarkScreamingSnake
BenchmarkScreamingSnake-10      2887975        415.8 ns/op      288 B/op        3 allocs/op
BenchmarkKebab
BenchmarkKebab-10               3232392        371.3 ns/op      288 B/op        3 allocs/op
BenchmarkCamelKebab
BenchmarkCamelKebab-10          3160936        382.2 ns/op      288 B/op        3 allocs/op
BenchmarkScreamingKebab
BenchmarkScreamingKebab-10      2873886        420.2 ns/op      288 B/op        3 allocs/op
BenchmarkLower
BenchmarkLower-10               3300728        369.9 ns/op      288 B/op        3 allocs/op
BenchmarkTitle
BenchmarkTitle-10               3079971        380.6 ns/op      288 B/op        3 allocs/op
BenchmarkScreaming
BenchmarkScreaming-10           2898652        417.5 ns/op      288 B/op        3 allocs/op
PASS

Documentation

Overview

Package casbab is a Go library for converting representation style of compound words or phrases. Different writing styles of compound words are used for different purposes in computer code and variables to easily distinguish type, properties or meaning.

Functions in this package are separating words from input string and constructing an appropriate phrase representation.

Examples:

Kebab("camel_snake_kebab") == "camel-snake-kebab"
ScreamingSnake("camel_snake_kebab") == "CAMEL_SNAKE_KEBAB"
Camel("camel_snake_kebab") == "camelSnakeKebab"
Pascal("camel_snake_kebab") == "CamelSnakeKebab"
Snake("camelSNAKEKebab") == "camel_snake_kebab"

Word separation works by detecting delimiters hyphen (-), underscore (_), space ( ) and letter case change.

Note: Leading and trailing separators will be preserved only within the Snake family or within the Kebab family and not across them. This restriction is based on different semantics between different writings.

Examples:

CamelSnake("__camel_snake_kebab__") == "__Camel_Snake_Kebab__"
Kebab("__camel_snake_kebab") == "camel-snake-kebab"
Screaming("__camel_snake_kebab") == "CAMEL SNAKE KEBAB"
CamelKebab("--camel-snake-kebab") == "--Camel-Snake-Kebab"
Snake("--camel-snake-kebab") == "camel_snake_kebab"
Screaming("--camel-snake-kebab") == "CAMEL SNAKE KEBAB"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Camel

func Camel(s string) string

Camel case is the practice of writing compound words or phrases such that each word or abbreviation in the middle of the phrase begins with a capital letter, with no spaces or hyphens.

Example: "camelSnakeKebab".

func CamelKebab

func CamelKebab(s string) string

CamelKebab case is a variant of Kebab case with each element's first letter uppercased.

Example: "Camel-Snake-Kebab".

func CamelSnake

func CamelSnake(s string) string

CamelSnake case is a variant of Camel case with each element's first letter uppercased.

Example: "Camel_Snake_Kebab".

func Kebab

func Kebab(s string) string

Kebab case is the practice of writing compound words or phrases in which the elements are separated with one hyphen character (-) and no spaces, with all element letters lowercased within the compound.

Example: "camel-snake-kebab".

func Lower

func Lower(s string) string

Lower is returning detected words, not in a compound form, but separated by one space character with all letters in lower case.

Example: "camel snake kebab".

func Pascal

func Pascal(s string) string

Pascal case is a variant of Camel case writing where the first letter of the first word is always capitalized.

Example: "CamelSnakeKebab".

func Screaming

func Screaming(s string) string

Screaming is returning detected words, not in a compound form, but separated by one space character with all letters in upper case.

Example: "CAMEL SNAKE KEBAB".

func ScreamingKebab

func ScreamingKebab(s string) string

ScreamingKebab case is a variant of Kebab case with all letters uppercased.

Example: "CAMEL-SNAKE-KEBAB".

func ScreamingSnake

func ScreamingSnake(s string) string

ScreamingSnake case is a variant of Camel case with all letters uppercased.

Example: "CAMEL_SNAKE_KEBAB".

func Snake

func Snake(s string) string

Snake case is the practice of writing compound words or phrases in which the elements are separated with one underscore character (_) and no spaces, with all element letters lowercased within the compound.

Example: "camel_snake_kebab".

func Title

func Title(s string) string

Title is returning detected words, not in a compound form, but separated by one space character with first character in all letters in upper case and all other letters in lower case.

Example: "Camel Snake Kebab".

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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