words

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 1 Imported by: 2

README

Words Package

The words package provides utilities for converting strings between different cases, handling initialisms, and splitting words based on specific rules.

The package aims to maximize performance and minimize dependencies. It doesn't use regular expressions.

Installation

To install the package, run:

go get github.com/bartdeboer/words

Functions

ToSnakeCase

Converts a given string to snake_case.

func ToSnakeCase(s string) string

Example:

fmt.Println(ToSnakeCase("ThisIsATest")) // Output: this_is_a_test
ToKebabCase

Converts a given string to kebab-case.

func ToKebabCase(s string) string

Example:

fmt.Println(ToKebabCase("ThisIsATest")) // Output: this-is-a-test
Capitalize

Capitalizes the first letter of a given string and converts the rest to lowercase.

func Capitalize(s string) string

Example:

fmt.Println(Capitalize("example")) // Output: Example
ToCapWords

Converts a given string to capitalized words, handling initialisms correctly.

func ToCapWords(s string) string

Example:

fmt.Println(ToCapWords("thisIsATest")) // Output: ThisIsATest
ToMixedCase

Converts a given string to mixedCase, handling initialisms correctly.

func ToMixedCase(s string) string

Example:

fmt.Println(ToMixedCase("thisIsATest")) // Output: thisIsATest
SplitWords

Splits a string into words based on transitions between alphanumeric and non-alphanumeric characters, as well as transitions between lowercase and uppercase characters.

func SplitWords(s string) []string

Example:

fmt.Println(SplitWords("ThisIsATest")) // Output: ["This", "Is", "A", "Test"]

Tests

go test ./...

Benchmarks

go test -bench=.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(s string) string

Capitalize capitalizes the first letter of a given string and converts the rest to lowercase. Example: "example" -> "Example"

func SplitWords

func SplitWords(s string) []string

SplitWords splits a string into words based on transitions between alphanumeric and non-alphanumeric characters, as well as transitions between lowercase and uppercase characters. Example: "ThisIsATest" -> ["This", "Is", "A", "Test"]

func ToCapWords

func ToCapWords(s string) string

ToCapWords converts a given string to capitalized words, handling initialisms correctly. Example: "thisIsATest" -> "ThisIsATest"

func ToKebabCase

func ToKebabCase(s string) string

ToKebabCase converts a given string to kebab-case. It splits words based on transitions between alphanumeric and non-alphanumeric characters, as well as transitions between lowercase and uppercase characters. Example: "ThisIsATest" -> "this-is-a-test"

func ToMixedCase

func ToMixedCase(s string) string

ToMixedCase converts a given string to mixedCase, handling initialisms correctly. Example: "thisIsATest" -> "thisIsATest"

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts a given string to snake_case. It splits words based on transitions between alphanumeric and non-alphanumeric characters, as well as transitions between lowercase and uppercase characters. Example: "ThisIsATest" -> "this_is_a_test"

Types

This section is empty.

Jump to

Keyboard shortcuts

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