stringx

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package stringx provides extra helpers to work with string.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptySlug            = errors.New("stringx: empty slug")
	ErrEmptyString          = errors.New("stringx: empty string")
	ErrGenerateRandomString = errors.New("stringx: failed to generate random string")
	ErrInvalidLength        = errors.New("stringx: invalid length")
	ErrInvalidInput         = errors.New("stringx: invalid input")
)

Functions

func CamelCaseToUnderscore

func CamelCaseToUnderscore(s string) string

CamelCaseToUnderscore returns camel case string s in underscore style. For example: FooBar -> foo_bar

func CapitalizeEachWord

func CapitalizeEachWord(s string) string

CapitalizeEachWord returns string s with each word capitalized. This function works on ASCII letters only.

func RandomPassword

func RandomPassword(length int) (string, error)

RandomPassword returns a random password for the given length.

func RandomString

func RandomString(length int) (string, error)

RandomString returns a string of random characters of length, using randomStringSource as the source for the string.

func RandomStringIgnoreError

func RandomStringIgnoreError(length int) string

RandomStringIgnoreError is a convenient method for RandomString.

func Slugify

func Slugify(s string) (string, error)

Slugify returns a string with all non-english letters and non-digits with '-'. For example, 'hello world' -> 'hello-world'.

func TrimExtraWhiteSpacesInOut added in v2.1.0

func TrimExtraWhiteSpacesInOut(s string) string

TrimExtraWhiteSpacesInOut returns a string with extra whitespaces surrounded each words removed. For example: " foo bar alice smith" -> "foo bar alice smith"

func UnderscoreToLowerCamelCase

func UnderscoreToLowerCamelCase(s string, t language.Tag) string

UnderscoreToLowerCamelCase returns the underscore string s in language t in lower camel case. For example: foo_bar -> fooBar

func UnderscoreToUpperCamelCase

func UnderscoreToUpperCamelCase(s string, t language.Tag) string

UnderscoreToUpperCamelCase returns the underscore string s in language t in all upper camel case. For example: foo_bar -> FooBar

Types

This section is empty.

Jump to

Keyboard shortcuts

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