caseconv

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

PkgGoDev Go Report Card Maintainability Test Coverage

caseconv

This is a Go Module for snake, kebab, camel, pascal case conversion.

It can be used like:

package main

import (
	"fmt"

	"github.com/dc0d/caseconv"
)

func main() {
	input := "The quick brown fox jumps over the lazy dog"

	fmt.Println(caseconv.ToCamel(input))
	fmt.Println(caseconv.ToPascal(input))
	fmt.Println(caseconv.ToKebab(input))
	fmt.Println(caseconv.ToSnake(input))
}

And the output would be:

theQuickBrownFoxJumpsOverTheLazyDog
TheQuickBrownFoxJumpsOverTheLazyDog
the-quick-brown-fox-jumps-over-the-lazy-dog
the_quick_brown_fox_jumps_over_the_lazy_dog

Most of test cases are from change-case node package - so far. But the goal was not to follow same conventions.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToCamel

func ToCamel(str string) string
Example
package main

import (
	"fmt"

	"github.com/ddkwork/golibrary/std/stream/caseconv"
)

func main() {
	fmt.Println(caseconv.ToCamel("Test String v2"))

}
Output:

testStringV2
Example (From_snake_case)
package main

import (
	"fmt"

	"github.com/ddkwork/golibrary/std/stream/caseconv"
)

func main() {
	fmt.Println(caseconv.ToCamel("test_string_v2"))

}
Output:

testStringV2
Example (From_upper_case)
package main

import (
	"fmt"

	"github.com/ddkwork/golibrary/std/stream/caseconv"
)

func main() {
	fmt.Println(caseconv.ToCamel("TEST STRING V2"))

}
Output:

testStringV2

func ToKebab

func ToKebab(str string) string
Example
package main

import (
	"fmt"

	"github.com/ddkwork/golibrary/std/stream/caseconv"
)

func main() {
	fmt.Println(caseconv.ToKebab("Test String v2"))

}
Output:

test-string-v2

func ToPascal

func ToPascal(str string) string
Example
package main

import (
	"fmt"

	"github.com/ddkwork/golibrary/std/stream/caseconv"
)

func main() {
	fmt.Println(caseconv.ToPascal("test String v2"))

}
Output:

TestStringV2

func ToSnake

func ToSnake(str string) string
Example
package main

import (
	"fmt"

	"github.com/ddkwork/golibrary/std/stream/caseconv"
)

func main() {
	fmt.Println(caseconv.ToSnake("test String v2"))

}
Output:

test_string_v2

Types

This section is empty.

Jump to

Keyboard shortcuts

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