package module
Version: v0.1.3 Latest Latest

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

Go to latest
Published: Nov 19, 2019 License: MIT Imports: 5 Imported by: 0



A text case converter

casec is a text case converter for programmers. casec now supports upper, lower, title, camel, pascal, snake, kebab (or lisp) cases.

It also provides case conversion library not only command line tool.


Using go get

Go version 1.10 or higher is required.

go get

If you want to only download the casec library

go get

Using homebrew

brew tap mingrammer/casec
brew install casec

Using .tar.gz archive

Download gzip file from Github Releases according to your OS. Then, copy the unzipped executable to under system path.



Convert all words to snake case.

$ casec -t snake

Convert all snake case to camel case.

$ casec -f snake -t camel internal.go

Convert only 20~50 lines from snake case to camel case.

$ casec -f snake -t camel -l 20:50 internal.go

Show how would have been converted. (dry-run)

$ casec -f snake -t kebab -n match.lisp

Convert all camel case to snake case except for words you don't want to convert. It is useful for preventing the keywords (reserved words) or conventions from converting.

$ casec -f snake -t pascal -i '^package|var|const|if|for|range|return|func|go$' redis.go

You can pass multiple ignore expressions.

$ casec -f snake -t pascal -i '^package|var|const|if|for|range|return|func|go$' -i '^github|com$' redis.go


See details in GoDoc

package main

import (


func main() {
    // Output: true
    // Output: false
    fmt.Println(casec.Invert("Invert Me"))
    // Output: iNVERT mE
    // Output: writeRune
    // Output: ip_address
    // Output: simple-json-parser

Known issues

casec separates the words with non-letters (except - and _) including . and / letters. So, the ignore option of casec can not recognize the dot-or-slash separated word (ex. "") as a single chunk. So if you want to prevent the import path of Go source code, for example, import "" from converting, you should pass the ignore expression as -i "^(github|com|mingrammer|cfmt)$".

Here is a (maybe) solution for solving this issue.

  1. Treat the string surrounded with quotes ("" or '') as a single word optionally.






View Source
const (
	SnakeDelimiter = '_'
	KebabDelimiter = '-'

Case-specific delimiter


This section is empty.


func Invert

func Invert(s string) string

Invert inverts the UPPERCASE to lowercase and vice versa

func IsCamel added in v0.1.0

func IsCamel(s string) bool

IsCamelCase checks the string is camelcase

func IsCaseOf

func IsCaseOf(c, s string) (bool, error)

IsCaseOf checks whether the string is a specific case

func IsKebab added in v0.1.0

func IsKebab(s string) bool

IsKebabCase checks the string is kebabcase

func IsLower added in v0.1.0

func IsLower(s string) bool

IsLowerCase checks the string is lowercase

func IsPascal added in v0.1.0

func IsPascal(s string) bool

IsPascalCase checks the string is pascalcase

func IsSnake added in v0.1.0

func IsSnake(s string) bool

IsSnakeCase checks the string is snakecase

func IsTitle added in v0.1.0

func IsTitle(s string) bool

IsTitleCase checks the string is titlecase

func IsUpper added in v0.1.0

func IsUpper(s string) bool

IsUpperCase checks the string is uppercase

func ToCamel added in v0.1.0

func ToCamel(s string) string

ToCamelCase converts the string to camelcase Use strings.Map?

func ToCaseFor

func ToCaseFor(c, s string) (string, error)

ToCaseFor converts the string to specific case

func ToKebab added in v0.1.0

func ToKebab(s string) string

ToKebabCase converts the string to kebabcase

func ToLower added in v0.1.0

func ToLower(s string) string

ToLowerCase converts the string to lowercase

func ToPascal added in v0.1.0

func ToPascal(s string) string

ToPascalCase converts the string to pascalcase

func ToSnake added in v0.1.0

func ToSnake(s string) string

ToSnakeCase converts the string to snakecase

func ToTitle added in v0.1.0

func ToTitle(s string) string

ToTitleCase converts the string to titlecase

func ToUpper added in v0.1.0

func ToUpper(s string) string

ToUpperCase converts the string to uppercase


This section is empty.

Source Files


Path Synopsis

Jump to

Keyboard shortcuts

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