cases

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: Apache-2.0 Imports: 3 Imported by: 14

Documentation

Overview

Package cases contains functions for Maping strings between various cases (snake, pascal, etc).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Title

func Title(s string) string

Title capitalizes the first letter of the string.

func Untitle

func Untitle(s string) string

Untitle lower-cases the first letter of the string.

Types

type Words

type Words []string

Words are a list of strings.

func Camel

func Camel(s string) Words

Camel separates and returns the words in s, where each new word begins with an uppercase letter. Camel parses identically to Pascal(), but is declared for symmetry with Words.ToCamel().

Example
fmt.Println(Camel("catSaysMeow"), Words{"cat", "says", "meow"}.ToCamel())
Output:

[cat Says Meow] catSaysMeow

func Pascal

func Pascal(s string) Words

Pascal separates and returns the words in s, where each word begins with a uppercase letter.

Example
fmt.Println(Pascal("CatSaysMeow"), Words{"cat", "says", "meow"}.ToPascal())
Output:

[Cat Says Meow] CatSaysMeow

func Snake

func Snake(s string) Words

Snake separates and returns the words in s by underscore.

Example
fmt.Println(Snake("cat_says_meow"), Words{"cat", "says", "meow"}.ToSnake())
Output:

[cat says meow] cat_says_meow

func (Words) Map

func (w Words) Map(f func(string) string) Words

Map returns a new list of words, each mapped by f.

func (Words) Title

func (w Words) Title() Words

Title capitalizes the first letter of each word.

func (Words) ToCamel

func (w Words) ToCamel() string

ToCamel returns all the words concatenated with each word beginning with an uppercase letter, except for the first.

func (Words) ToLower

func (w Words) ToLower() Words

ToLower converts all the words to lowercase.

func (Words) ToPascal

func (w Words) ToPascal() string

ToPascal returns all the words concatenated with each word beginning with an uppercase letter.

func (Words) ToSnake

func (w Words) ToSnake() string

ToSnake returns all the words concatenated with an underscore.

func (Words) ToUpper

func (w Words) ToUpper() Words

ToUpper converts all the words to uppercase.

func (Words) Untitle

func (w Words) Untitle() Words

Untitle lower-cases the first letter of each word.

Jump to

Keyboard shortcuts

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