https://github.com/mingrammer/casec
:rainbow: A text case converter
https://github.com/mingrammer/casec
case case-converter cli go
Last synced: about 1 month ago
JSON representation
:rainbow: A text case converter
- Host: GitHub
- URL: https://github.com/mingrammer/casec
- Owner: mingrammer
- License: mit
- Created: 2018-02-11T06:28:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-19T14:27:46.000Z (over 5 years ago)
- Last Synced: 2024-06-20T17:54:06.390Z (12 months ago)
- Topics: case, case-converter, cli, go
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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/casec
```### Using [homebrew](https://brew.sh)
```
brew tap mingrammer/casec
brew install casec
```### Using .tar.gz archive
Download gzip file from [Github Releases](https://github.com/mingrammer/casec/releases/latest) according to your OS. Then, copy the unzipped executable to under system path.
## Usage
### CLI
Convert all words to snake case.
```bash
$ casec -t snake main.py
```Convert all snake case to camel case.
```bash
$ casec -f snake -t camel internal.go
```Convert only 20~50 lines from snake case to camel case.
```bash
$ casec -f snake -t camel -l 20:50 internal.go
```Show how would have been converted. (dry-run)
```bash
$ 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.
```bash
$ casec -f snake -t pascal -i '^package|var|const|if|for|range|return|func|go$' redis.go
```You can pass multiple ignore expressions.
```bash
$ 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](https://godoc.org/github.com/mingrammer/casec)
```go
package mainimport (
"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