Common case conversions covering common initialisms.

kace

go get "github.com/codemodus/kace"

Package kace provides common case conversion functions which take into consideration common initialisms.

Usage

func Camel(s string) string
func Kebab(s string) string
func KebabUpper(s string) string
func Pascal(s string) string
func Snake(s string) string
func SnakeUpper(s string) string
type Kace
    func New(initialisms map[string]bool) (*Kace, error)
    func (k *Kace) Camel(s string) string
    func (k *Kace) Kebab(s string) string
    func (k *Kace) KebabUpper(s string) string
    func (k *Kace) Pascal(s string) string
    func (k *Kace) Snake(s string) string
    func (k *Kace) SnakeUpper(s string) string

Setup

import (
    "fmt"

    "github.com/codemodus/kace"
)

func main() {
    s := "this is a test sql."

    fmt.Println(kace.Camel(s))
    fmt.Println(kace.Pascal(s))

    fmt.Println(kace.Snake(s))
    fmt.Println(kace.SnakeUpper(s))

    fmt.Println(kace.Kebab(s))
    fmt.Println(kace.KebabUpper(s))

    customInitialisms := map[string]bool{
        "THIS": true,
    }
    k, err := kace.New(customInitialisms)
    if err != nil {
        // handle error
    }

    fmt.Println(k.Camel(s))
    fmt.Println(k.Pascal(s))

    fmt.Println(k.Snake(s))
    fmt.Println(k.SnakeUpper(s))

    fmt.Println(k.Kebab(s))
    fmt.Println(k.KebabUpper(s))

    // Output:
    // thisIsATestSQL
    // ThisIsATestSQL
    // this_is_a_test_sql
    // THIS_IS_A_TEST_SQL
    // this-is-a-test-sql
    // THIS-IS-A-TEST-SQL
    // thisIsATestSql
    // THISIsATestSql
    // this_is_a_test_sql
    // THIS_IS_A_TEST_SQL
    // this-is-a-test-sql
    // THIS-IS-A-TEST-SQL
}

More Info

TODO

Test Trie

Test the current trie.

Documentation

View the GoDoc

Benchmarks

benchmark                 iter       time/iter   bytes alloc        allocs
---------                 ----       ---------   -----------        ------
BenchmarkCamel4        2000000    947.00 ns/op      112 B/op   3 allocs/op
BenchmarkSnake4        2000000    696.00 ns/op      128 B/op   2 allocs/op
BenchmarkSnakeUpper4   2000000    679.00 ns/op      128 B/op   2 allocs/op
BenchmarkKebab4        2000000    691.00 ns/op      128 B/op   2 allocs/op
BenchmarkKebabUpper4   2000000    677.00 ns/op      128 B/op   2 allocs/op
Comments
  • User-defined initialisms.

    User-defined initialisms.

    From @natefinch in #2

    I'd also like to have any functions that need to use the intiialisms list to have an alternate form that takes a customized list.

  • snake->camel/pascal misuses initialisms

    snake->camel/pascal misuses initialisms

    for example:

    foo_identifier gets turned into FooIDentifier instead of FooIdentifier

    I tried to look at the code to propose a fix but I honestly can't follow what it's doing.

  • Suggest splitting CamelCase into 2 functions

    Suggest splitting CamelCase into 2 functions

    It can make a big difference in usability to avoid using booleans in function signatures, since it's impossible to tell what true or false mean when you're just reading code.

    I suggest using CamelCase and PascalCase as function names (where PascalCase is the first upper and camel is first lower).

    I'd also like to have any functions that need to use the intiialisms list to have an alternate form that takes a customized list.

    I'm happy to make PRs for any of this.

  • Camel case

    Camel case

    Transformation to lower camel case does not work if your first character is upper case.

    e. g. Camel("NotAwesome",false) returns "NotAwesome" instead of "notAwesome".

  • Split Camel into two functions

    Split Camel into two functions

    This change splits the Camel into two functions, to avoid using a boolean to define behavior. Now it is two functions - Camel for lowercase first letter and Pascal for uppercase first letter.

    Also some small tweaking of doc strings.

  • Common initialisms in kace.Snake

    Common initialisms in kace.Snake

    Hi,

    Thanks for sharing this package. Do you think it is possible to support common initialisms in kace.Snake as well? For example:

    fmt.Println(kace.Pascal("http url"), kace.Snake(kace.Pascal("http url")))
    // HTTPURL httpurl
    

    The expected output is HTTPURL http_url. This is needed for generating SQL column names from Go field names.

Related tags
Myretail-target-case-study - Case study assessment for Target.com

myRetail This project contains two solutions to the Target myRetail case study. The prompt is copied over to PROMPT.md for convenience, but the TLDR i

Jan 1, 2022
Donald Knuth's Algorithm 7.2.2.1M for covering with multiplicities and colors via dancing links

Covering with multiplicities and colors via Dancing Links Go implementation of Donald Knuth's Algorithm 7.2.2.1M for covering with multiplicities and

Dec 14, 2022
Covering basics of Go by writing practical running code. microservice-http server-DAO-Kafka

go1 Covering all basics of Go by writing practical running code. Prerequisite: basic knowledge of c programming language as go is very similar to c in

Mar 30, 2022
Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.

go-finance Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds

Jan 2, 2023
Fast conversions across various Go types with a simple API.

Go Package: conv Get: go get -u github.com/cstockton/go-conv Example: // Basic types if got, err := conv.Bool(`TRUE`); err == nil { fmt.Printf("conv.

Nov 29, 2022
Remove unnecessary type conversions from Go source

About The unconvert program analyzes Go packages to identify unnecessary type conversions; i.e., expressions T(x) where x already has type T. Install

Nov 28, 2022
A safe way to execute functions asynchronously, recovering them in case of panic. It also provides an error stack aiming to facilitate fail causes discovery.

Async Provides a safe way to execute functions asynchronously, recovering them in case of panic. It also provides an error stack aiming to facilitate

Dec 20, 2022
A command line http test tool. Maintain the case via git and pure text
A command line http test tool. Maintain the case via git and pure text

httptest A command line http test tool Maintain the api test cases via git and pure text We want to test the APIs via http requests and assert the res

Dec 16, 2022
Package strnaming is used to Convert string to camelCase, snake_case, kebab-case.

strnaming Package strnaming is used to Convert string to camelCase, snake_case, kebab-case. Contents strnaming Contents API Examples Install Quick sta

Oct 24, 2021
Handle any SQS use case, monitor any queue. Reusable for any project! Invoke in a goroutine to process SQS messages.

GOSQS This package is intended to be a Go SQS listener that can be imported and invoked as a goroutine handled by the life cycle of your service. It's

Dec 22, 2021
800k lines switch case cpp challenge
800k lines switch case cpp challenge

800k lines cpp compile challenge 80万行cpp编译挑战 800k lines cpp 编译 challenge generate 生成Cpp代码 go run generator.go compile 编译Cpp代码 g++ -m64 main.cpp binary

Oct 27, 2021
Golang JSON decoder supporting case-sensitive, number-preserving, and strict decoding use cases

Golang JSON decoder supporting case-sensitive, number-preserving, and strict decoding use cases

Dec 9, 2022
Project test case recruitment kanggo

Kanggo Project test case recruitment kanggo Installation Need golang to run go run main.go .env file will be served Admin Account email:[email protected]

Nov 20, 2021
Spawning up Decoy Server in case of any fraudulent activity and directing the intruder towards the decoy. Auto Killing the decoy if it is idle for too long.
Spawning up Decoy Server in case of any fraudulent activity and directing the intruder towards the decoy. Auto Killing the decoy if it is idle for too long.

SecureX Spawning up Decoy Server in case of any fraudulent activity and directing the intruder towards the decoy. Auto Killing the decoy if it is idle

Jul 9, 2022
idk, i'm just passed the function test case :D

Challenge Create an API that crawl links from given URL using GoLang or NodeJS. You can use any framework or libraries but your program should be can

Dec 23, 2021
yemek-sepeti-golang-case

yemek-sepeti-golang-case yemek-sepeti-golang-case Overview This Project Developed With Using Domain Driven Design , Factory Pattern , Repository Patte

Jan 16, 2022
wholeaked is a file-sharing tool that allows you to find the responsible person in case of a leakage
wholeaked is a file-sharing tool that allows you to find the responsible person in case of a leakage

wholeaked is a file-sharing tool that allows you to find the responsible person in case of a leakage

Dec 25, 2022
Drain-my-spot - Service draining the k8s worker node in case of spot instances related event occurrence

drain-my-spot Service draining the k8s worker node in case of spot instances rel

Feb 5, 2022
Bcfm-study-case - A simple http server using the Echo library in Go language
Bcfm-study-case - A simple http server using the Echo library in Go language

Task 1 Hakkında Burada Go dilinde Echo kütüphanesini kullanarak basit bir http s

Feb 2, 2022