casec

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: MIT Imports: 5 Imported by: 0

README



Casec

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.

Installation

Using go get

Go version 1.10 or higher is required.

go get github.com/mingrammer/casec/...

If you want to only download the casec library

go get github.com/mingrammer/case

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.

Usage

CLI

Convert all words to snake case.

$ casec -t snake main.py

Convert all snake case to camel case.

$ casec -f snake -t camel internal.go

Show diff between before and after conversion without actually applying.

$ casec -f snake -t kebab -d 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

Library

See details in GoDoc

package main

import (
    "fmt"

    "github.com/mingrammer/casec"
)

func main() {
    fmt.Println(casec.IsSnakeCase("this_is_snake"))
    // Output: true
    fmt.Println(casec.IsCamelCase("thisIsNot_camelCase"))
    // Output: false
    fmt.Println(casec.Invert("Invert Me"))
    // Output: iNVERT mE
    fmt.Println(casec.ToSnakeCase("IPAddress"))
    // Output: ip_address
}

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. "github.com/mingrammer/cfmt") as a single chunk. So if you want to prevent the import path of Go source code, for example, import "github.com/mingrammer/cfmt" from converting, you should pass the ignore expression as -i "^github|com|mingrammer|cfmt$".

Here are the solutions that I'll consider making it an option for solving this issue.

  1. Treat the string surrounded with quotes ("" or '') as a single word optionally.
  2. Make an option for specifying the line number ranges for applying the conversion.

License

MIT

Documentation

Index

Constants

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

Case-specific delimiter

Variables

This section is empty.

Functions

func Invert

func Invert(s string) string

Invert inverts the UPPERCASE to lowercase and vice versa

func IsCamelCase

func IsCamelCase(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 IsKebabCase

func IsKebabCase(s string) bool

IsKebabCase checks the string is kebabcase

func IsLowerCase

func IsLowerCase(s string) bool

IsLowerCase checks the string is lowercase

func IsPascalCase

func IsPascalCase(s string) bool

IsPascalCase checks the string is pascalcase

func IsSnakeCase

func IsSnakeCase(s string) bool

IsSnakeCase checks the string is snakecase

func IsTitleCase

func IsTitleCase(s string) bool

IsTitleCase checks the string is titlecase

func IsUpperCase

func IsUpperCase(s string) bool

IsUpperCase checks the string is uppercase

func ToCamelCase

func ToCamelCase(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 ToKebabCase

func ToKebabCase(s string) string

ToKebabCase converts the string to kebabcase

func ToLowerCase

func ToLowerCase(s string) string

ToLowerCase converts the string to lowercase

func ToPascalCase

func ToPascalCase(s string) string

ToPascalCase converts the string to pascalcase

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts the string to snakecase

func ToTitleCase

func ToTitleCase(s string) string

ToTitleCase converts the string to titlecase

func ToUpperCase

func ToUpperCase(s string) string

ToUpperCase converts the string to uppercase

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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