textcase

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2022 License: MIT Imports: 4 Imported by: 18

README

textcase

GoDoc Widget

Golang pkg to convert any text input to camelCase, PascalCase, snake_case or kebab-case naming convention. Removes all whitespaces and special characters. Supports Unicode characters.

Usage

import "github.com/golang-cz/textcase"

textcase.CamelCase("Hello World!")
// helloWorld

textcase.PascalCase("Hello World!")
// HelloWorld

textcase.SnakeCase("Hello World!")
// hello_world

textcase.KebabCase("Hello World!")
// hello-world

Unicode support

textcase.CamelCase("Háčky, čárky. Příliš žluťoučký kůň úpěl ďábelské ódy.")
// háčkyČárkyPřílišŽluťoučkýKůňÚpělĎábelskéÓdy
Possible Unicode limitations
textcase.CamelCase("Here comes O'Brian")
// hereComesOBrian

This package doesn't implement language-specific case mappers, such as golang.org/x/text/cases, and thus comes with a similar limitation to strings.Title(). But given the likely use cases of this package, we deliberately chose English version hereComesOBrian over hereComesObrian for the above Here comes O'Brian input.

License

Licensed under MIT License

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(input string) string

Converts input string to "camelCase" (lower camel case) naming convention. Removes all whitespace and special characters. Supports Unicode characters.

Example
package main

import (
	"fmt"

	"github.com/golang-cz/textcase"
)

func main() {
	fmt.Println(textcase.CamelCase("Hello World!"))
}
Output:

helloWorld

func KebabCase added in v1.1.0

func KebabCase(input string) string

Converts input string to "kebab-case" naming convention. Removes all whitespace and special characters. Supports Unicode characters.

Example
package main

import (
	"fmt"

	"github.com/golang-cz/textcase"
)

func main() {
	fmt.Println(textcase.KebabCase("Hello World!"))
}
Output:

hello-world

func PascalCase

func PascalCase(input string) string

Converts input string to "PascalCase" (upper camel case) naming convention. Removes all whitespace and special characters. Supports Unicode characters.

Example
package main

import (
	"fmt"

	"github.com/golang-cz/textcase"
)

func main() {
	fmt.Println(textcase.PascalCase("Hello World!"))
}
Output:

HelloWorld

func SnakeCase

func SnakeCase(input string) string

Converts input string to "snake_case" naming convention. Removes all whitespace and special characters. Supports Unicode characters.

Example
package main

import (
	"fmt"

	"github.com/golang-cz/textcase"
)

func main() {
	fmt.Println(textcase.SnakeCase("Hello World!"))
}
Output:

hello_world

Types

This section is empty.

Jump to

Keyboard shortcuts

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