Giter VIP home page Giter VIP logo

casec's Introduction



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/casec

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

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

Library

See details in GoDoc

package main

import (
    "fmt"

    "github.com/mingrammer/casec"
)

func main() {
    fmt.Println(casec.IsSnake("this_is_snake"))
    // Output: true
    fmt.Println(casec.IsCamel("thisIsNot_camelCase"))
    // Output: false
    fmt.Println(casec.Invert("Invert Me"))
    // Output: iNVERT mE
    fmt.Println(casec.ToCamel("write_rune"))
    // Output: writeRune
    fmt.Println(casec.ToSnake("IPAddress"))
    // Output: ip_address
    fmt.Println(casec.ToKebab("simpleJSONParser"))
    // 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. "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 is a (maybe) solution for solving this issue.

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

License

MIT

casec's People

Contributors

mingrammer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

robrepp

casec's Issues

Remove ”Case” postfix?

”Case” postfix seems unnecessary for all case conversion APIs.

I think it should follow the conventions of func naming of standard packages such as unicode.IsUpper and strings.ToLower.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.