str

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After(subject, search string) string

After returns the substring after the first occurrence of the given value. If the value doesn't exist, returns the entire string.

func AfterLast

func AfterLast(subject, search string) string

AfterLast returns the substring after the last occurrence of the given value. If the value doesn't exist, returns the entire string.

func Ascii

func Ascii(value string) string

Ascii transliterates a UTF-8 value to ASCII.

func Before

func Before(subject, search string) string

Before returns the substring before the first occurrence of the given value. If the value doesn't exist, returns the entire string.

func BeforeLast

func BeforeLast(subject, search string) string

BeforeLast returns the substring before the last occurrence of the given value. If the value doesn't exist, returns the entire string.

func Between

func Between(subject, from, to string) string

Between returns the substring between two strings.

func BetweenFirst

func BetweenFirst(subject, from, to string) string

BetweenFirst returns the smallest possible substring between two strings.

func Camel

func Camel(value string) string

Camel converts the string to camelCase.

func Contains

func Contains(haystack string, needles ...string) bool

Contains checks if the string contains the given value(s).

func ContainsAll

func ContainsAll(haystack string, needles []string) bool

ContainsAll checks if the string contains all of the given values.

func EndsWith

func EndsWith(haystack string, needles ...string) bool

EndsWith checks if the string ends with any of the given values.

func Exactly

func Exactly(subject, value string) bool

Exactly checks if the string exactly matches the given value.

func Excerpt

func Excerpt(text, phrase string, options ...ExcerptOptions) string

func Finish

func Finish(value, cap string) string

Finish ensures a string ends with a given value.

func Headline

func Headline(value string) string

Headline converts the string to a human-readable headline.

func InlineMarkdown

func InlineMarkdown(str string) string

InlineMarkdown removes all Markdown formatting from the given string.

func Is

func Is(pattern, value string) bool

Is checks if the string matches the given pattern.

func IsAscii

func IsAscii(value string) bool

IsAscii checks if the string is 7-bit ASCII.

func IsJson

func IsJson(value string) bool

IsJson checks if the string is valid JSON.

func IsUlid

func IsUlid(value string) bool

IsUlid checks if the string is a valid ULID.

func IsUrl

func IsUrl(value string) bool

IsUrl checks if the string is a valid URL.

func IsUuid

func IsUuid(value string) bool

IsUuid checks if the string is a valid UUID.

func Kebab

func Kebab(value string) string

Kebab converts the string to kebab-case.

func Length

func Length(value string) int

Length returns the length of the string (UTF-8 aware).

func Limit

func Limit(value string, limit int, end ...string) string

Limit limits the number of characters in a string.

func Lower

func Lower(value string) string

Lower converts the string to lowercase.

func Ltrim

func Ltrim(value string, characters ...string) string

Ltrim trims the left side of the string.

func Markdown

func Markdown(str string) string

Markdown converts inline Markdown to HTML.

func Mask

func Mask(str string, character rune, index int, length ...int) string

Mask masks a portion of a string with a repeated character.

func Match

func Match(pattern, value string) bool

Match performs a pattern match on the string.

func MatchAll

func MatchAll(pattern, subject string) [][]string

MatchAll performs a global pattern match on the string.

func PadBoth

func PadBoth(value string, length int, pad ...string) string

PadBoth pads both sides of the string.

func PadLeft

func PadLeft(value string, length int, pad ...string) string

PadLeft pads the left side of the string.

func PadRight

func PadRight(value string, length int, pad ...string) string

PadRight pads the right side of the string.

func Plural

func Plural(value string, count ...float64) string

Plural returns the plural form of a word.

func Position

func Position(haystack, needle string) int

Position finds the position of the first occurrence of a substring.

func Random

func Random(length ...int) string

Random generates a random string of the specified length.

func Repeat

func Repeat(str string, times int) string

Repeat repeats the string.

func Replace

func Replace(search, replace, subject string) string

Replace replaces all occurrences of the search string with the replacement string.

func ReplaceArray

func ReplaceArray(search, replace []string, subject string) string

ReplaceArray replaces the occurrences of search array with replace array sequentially.

func ReplaceFirst

func ReplaceFirst(search, replace, subject string) string

ReplaceFirst replaces the first occurrence of the search string with the replacement string.

func ReplaceLast

func ReplaceLast(search, replace, subject string) string

ReplaceLast replaces the last occurrence of the search string with the replacement string.

func Reverse

func Reverse(value string) string

Reverse reverses the string (UTF-8 aware).

func Rtrim

func Rtrim(value string, characters ...string) string

Rtrim trims the right side of the string.

func Singular

func Singular(value string) string

Singular returns the singular form of a word.

func Slug

func Slug(title string, separator ...string) string

Slug generates a URL-friendly "slug" from the given string.

func Snake

func Snake(value string) string

Snake converts the string to snake_case.

func Squish

func Squish(str string) string

Squish removes all extraneous white space from a string including unicode spaces.

func SquishFast

func SquishFast(str string) string

SquishFast removes all extraneous white space from a string quickly.

func Start

func Start(value, prefix string) string

Start ensures a string starts with a given value.

func StartsWith

func StartsWith(haystack string, needles ...string) bool

StartsWith checks if the string starts with any of the given values.

func Studly

func Studly(value string) string

Studly converts the string to StudlyCase (PascalCase).

func Substr

func Substr(str string, start int, length ...int) string

Substr returns a substring starting at the given position.

func SubstrCount

func SubstrCount(haystack, needle string) int

SubstrCount counts the occurrences of a substring.

func SubstrReplace

func SubstrReplace(str, replace string, offset int, length ...int) string

SubstrReplace replaces text within a portion of a string.

func Swap

func Swap(pairs map[string]string, subject string) string

Swap replaces multiple values in the string using a map.

func Take

func Take(str string, limit int) string

Take returns the first n characters of the string.

func Test

func Test(pattern, value string) bool

Test checks if the string matches the given pattern.

func Title

func Title(value string) string

Title converts the string to title case.

func Trim

func Trim(value string, characters ...string) string

Trim trims the string of the given characters.

func Ucfirst

func Ucfirst(str string) string

Ucfirst makes the string's first character uppercase.

func Ucsplit

func Ucsplit(str string) []string

Ucsplit splits the string by uppercase characters.

func Upper

func Upper(value string) string

Upper converts the string to uppercase.

func When

func When(condition bool, value string, callback func(string) string, defaultCallback ...func(string) string) string

When applies the callback if the given condition is true.

func WhenContains

func WhenContains(haystack, needle string, callback func(string) string, defaultCallback ...func(string) string) string

WhenContains applies the callback if the string contains the given value.

func WhenContainsAll

func WhenContainsAll(haystack string, needles []string, callback func(string) string, defaultCallback ...func(string) string) string

WhenContainsAll applies the callback if the string contains all given values.

func WhenEmpty

func WhenEmpty(value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenEmpty applies the callback if the string is empty.

func WhenEndsWith

func WhenEndsWith(haystack string, needles []string, callback func(string) string, defaultCallback ...func(string) string) string

WhenEndsWith applies the callback if the string ends with the given value.

func WhenExactly

func WhenExactly(subject, value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenExactly applies the callback if the string exactly matches the given value.

func WhenIs

func WhenIs(pattern, value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenIs applies the callback if the string matches the given pattern.

func WhenIsAscii

func WhenIsAscii(value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenIsAscii applies the callback if the string is ASCII.

func WhenIsUlid

func WhenIsUlid(value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenIsUlid applies the callback if the string is a valid ULID.

func WhenIsUuid

func WhenIsUuid(value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenIsUuid applies the callback if the string is a valid UUID.

func WhenNotEmpty

func WhenNotEmpty(value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenNotEmpty applies the callback if the string is not empty.

func WhenNotExactly

func WhenNotExactly(subject, value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenNotExactly applies the callback if the string does not exactly match the given value.

func WhenStartsWith

func WhenStartsWith(haystack string, needles []string, callback func(string) string, defaultCallback ...func(string) string) string

WhenStartsWith applies the callback if the string starts with the given value.

func WhenTest

func WhenTest(pattern, value string, callback func(string) string, defaultCallback ...func(string) string) string

WhenTest applies the callback if the string matches the given regular expression.

func WordCount

func WordCount(str string) int

WordCount counts the words in the string.

func WordWrap

func WordWrap(str string, width int, breakStr ...string) string

WordWrap wraps the string at the given length.

func Words

func Words(value string, words int, end ...string) string

Words limits the number of words in a string.

Types

type ExcerptOptions

type ExcerptOptions struct {
	Radius   int
	Omission string
}

Excerpt extracts an excerpt from text that matches the given phrase.

type Stringable

type Stringable struct {
	// contains filtered or unexported fields
}

Stringable provides a fluent interface for string manipulation.

func Of

func Of(value interface{}) *Stringable

Of creates a new Stringable instance with the given value.

func (*Stringable) After

func (s *Stringable) After(search string) *Stringable

After returns the substring after the first occurrence of the given value.

func (*Stringable) AfterLast

func (s *Stringable) AfterLast(search string) *Stringable

AfterLast returns the substring after the last occurrence of the given value.

func (*Stringable) Append

func (s *Stringable) Append(values ...string) *Stringable

Append appends the given values to the string.

func (*Stringable) Ascii

func (s *Stringable) Ascii() *Stringable

Ascii transliterates the string to ASCII.

func (*Stringable) Basename

func (s *Stringable) Basename(suffix ...string) *Stringable

Basename returns the trailing name component of a path.

func (*Stringable) Before

func (s *Stringable) Before(search string) *Stringable

Before returns the substring before the first occurrence of the given value.

func (*Stringable) BeforeLast

func (s *Stringable) BeforeLast(search string) *Stringable

BeforeLast returns the substring before the last occurrence of the given value.

func (*Stringable) Between

func (s *Stringable) Between(from, to string) *Stringable

Between returns the substring between two strings.

func (*Stringable) BetweenFirst

func (s *Stringable) BetweenFirst(from, to string) *Stringable

BetweenFirst returns the smallest possible substring between two strings.

func (*Stringable) Camel

func (s *Stringable) Camel() *Stringable

Camel converts the string to camelCase.

func (*Stringable) CharAt

func (s *Stringable) CharAt(index int) string

CharAt returns the character at the given index.

func (*Stringable) ClassBasename

func (s *Stringable) ClassBasename() *Stringable

ClassBasename returns the class basename of the class path.

func (*Stringable) Contains

func (s *Stringable) Contains(needles ...string) bool

Contains checks if the string contains the given value(s).

func (*Stringable) ContainsAll

func (s *Stringable) ContainsAll(needles []string) bool

ContainsAll checks if the string contains all of the given values.

func (*Stringable) Dirname

func (s *Stringable) Dirname(levels ...int) *Stringable

Dirname returns the directory name from a path.

func (*Stringable) EndsWith

func (s *Stringable) EndsWith(needles ...string) bool

EndsWith checks if the string ends with any of the given values.

func (*Stringable) Exactly

func (s *Stringable) Exactly(value string) bool

Exactly checks if the string exactly matches the given value.

func (*Stringable) Excerpt

func (s *Stringable) Excerpt(phrase string, options ...ExcerptOptions) *Stringable

Excerpt extracts an excerpt from text that matches the given phrase.

func (*Stringable) Explode

func (s *Stringable) Explode(delimiter string, limit ...int) []string

Explode splits the string by the given delimiter.

func (*Stringable) Finish

func (s *Stringable) Finish(cap string) *Stringable

Finish ensures the string ends with the given value.

func (*Stringable) Headline

func (s *Stringable) Headline() *Stringable

Headline converts the string to a human-readable headline.

func (*Stringable) InlineMarkdown

func (s *Stringable) InlineMarkdown() *Stringable

InlineMarkdown removes all Markdown formatting from the string.

func (*Stringable) Is

func (s *Stringable) Is(pattern string) bool

Is checks if the string matches the given pattern.

func (*Stringable) IsAscii

func (s *Stringable) IsAscii() bool

IsAscii checks if the string is 7-bit ASCII.

func (*Stringable) IsEmpty

func (s *Stringable) IsEmpty() bool

IsEmpty checks if the string is empty.

func (*Stringable) IsJson

func (s *Stringable) IsJson() bool

IsJson checks if the string is valid JSON.

func (*Stringable) IsNotEmpty

func (s *Stringable) IsNotEmpty() bool

IsNotEmpty checks if the string is not empty.

func (*Stringable) IsUlid

func (s *Stringable) IsUlid() bool

IsUlid checks if the string is a valid ULID.

func (*Stringable) IsUrl

func (s *Stringable) IsUrl() bool

IsUrl checks if the string is a valid URL.

func (*Stringable) IsUuid

func (s *Stringable) IsUuid() bool

IsUuid checks if the string is a valid UUID.

func (*Stringable) Kebab

func (s *Stringable) Kebab() *Stringable

Kebab converts the string to kebab-case.

func (*Stringable) LcFirst

func (s *Stringable) LcFirst() *Stringable

LcFirst makes the string's first character lowercase.

func (*Stringable) Length

func (s *Stringable) Length() int

Length returns the length of the string.

func (*Stringable) Limit

func (s *Stringable) Limit(limit int, end ...string) *Stringable

Limit limits the number of characters in the string.

func (*Stringable) Lower

func (s *Stringable) Lower() *Stringable

Lower converts the string to lowercase.

func (*Stringable) Ltrim

func (s *Stringable) Ltrim(characters ...string) *Stringable

Ltrim trims the left side of the string.

func (*Stringable) Markdown

func (s *Stringable) Markdown() *Stringable

Markdown converts inline Markdown to HTML.

func (*Stringable) Mask

func (s *Stringable) Mask(character rune, index int, length ...int) *Stringable

Mask masks a portion of the string with a repeated character.

func (*Stringable) Match

func (s *Stringable) Match(pattern string) bool

Match performs a pattern match on the string.

func (*Stringable) MatchAll

func (s *Stringable) MatchAll(pattern string) [][]string

MatchAll performs a global pattern match on the string.

func (*Stringable) NewLine

func (s *Stringable) NewLine(count ...int) *Stringable

NewLine appends a newline to the string.

func (*Stringable) PadBoth

func (s *Stringable) PadBoth(length int, pad ...string) *Stringable

PadBoth pads both sides of the string.

func (*Stringable) PadLeft

func (s *Stringable) PadLeft(length int, pad ...string) *Stringable

PadLeft pads the left side of the string.

func (*Stringable) PadRight

func (s *Stringable) PadRight(length int, pad ...string) *Stringable

PadRight pads the right side of the string.

func (*Stringable) Pipe

func (s *Stringable) Pipe(callback func(string) interface{}) interface{}

Pipe passes the string to the given callback and returns the result.

func (*Stringable) Plural

func (s *Stringable) Plural(count ...float64) *Stringable

Plural returns the plural form of a word.

func (*Stringable) Position

func (s *Stringable) Position(needle string) int

Position finds the position of the first occurrence of a substring.

func (*Stringable) Prepend

func (s *Stringable) Prepend(values ...string) *Stringable

Prepend prepends the given values to the string.

func (*Stringable) Remove

func (s *Stringable) Remove(values ...string) *Stringable

Remove removes the given value(s) from the string.

func (*Stringable) Repeat

func (s *Stringable) Repeat(times int) *Stringable

Repeat repeats the string.

func (*Stringable) Replace

func (s *Stringable) Replace(search, replace string) *Stringable

Replace replaces all occurrences of the search string with the replacement string.

func (*Stringable) ReplaceArray

func (s *Stringable) ReplaceArray(search, replace []string) *Stringable

ReplaceArray replaces the occurrences of search array with replace array.

func (*Stringable) ReplaceFirst

func (s *Stringable) ReplaceFirst(search, replace string) *Stringable

ReplaceFirst replaces the first occurrence of the search string.

func (*Stringable) ReplaceLast

func (s *Stringable) ReplaceLast(search, replace string) *Stringable

ReplaceLast replaces the last occurrence of the search string.

func (*Stringable) ReplaceMatches

func (s *Stringable) ReplaceMatches(pattern, replace string) *Stringable

ReplaceMatches replaces matches of the pattern with the replacement.

func (*Stringable) Reverse

func (s *Stringable) Reverse() *Stringable

Reverse reverses the string.

func (*Stringable) Rtrim

func (s *Stringable) Rtrim(characters ...string) *Stringable

Rtrim trims the right side of the string.

func (*Stringable) Scan

func (s *Stringable) Scan(format string, args ...interface{}) (int, error)

Scan parses the string according to the given format.

func (*Stringable) Singular

func (s *Stringable) Singular() *Stringable

Singular returns the singular form of a word.

func (*Stringable) Slug

func (s *Stringable) Slug(separator ...string) *Stringable

Slug generates a URL-friendly "slug" from the string.

func (*Stringable) Snake

func (s *Stringable) Snake() *Stringable

Snake converts the string to snake_case.

func (*Stringable) Split

func (s *Stringable) Split(delimiter string) []string

Split splits the string by the given delimiter.

func (*Stringable) Squish

func (s *Stringable) Squish() *Stringable

Squish removes all extraneous white space from the string.

func (*Stringable) Start

func (s *Stringable) Start(prefix string) *Stringable

Start ensures the string starts with the given value.

func (*Stringable) StartsWith

func (s *Stringable) StartsWith(needles ...string) bool

StartsWith checks if the string starts with any of the given values.

func (*Stringable) String

func (s *Stringable) String() string

String returns the underlying string value.

func (*Stringable) Studly

func (s *Stringable) Studly() *Stringable

Studly converts the string to StudlyCase.

func (*Stringable) Substr

func (s *Stringable) Substr(start int, length ...int) *Stringable

Substr returns a substring starting at the given position.

func (*Stringable) SubstrCount

func (s *Stringable) SubstrCount(needle string) int

SubstrCount counts the occurrences of a substring.

func (*Stringable) SubstrReplace

func (s *Stringable) SubstrReplace(replace string, offset int, length ...int) *Stringable

SubstrReplace replaces text within a portion of the string.

func (*Stringable) Swap

func (s *Stringable) Swap(pairs map[string]string) *Stringable

Swap replaces multiple values in the string using a map.

func (*Stringable) Take

func (s *Stringable) Take(limit int) *Stringable

Take returns the first or last n characters of the string.

func (*Stringable) Tap

func (s *Stringable) Tap(callback func(*Stringable)) *Stringable

Tap passes the string to the given callback and returns the Stringable.

func (*Stringable) Test

func (s *Stringable) Test(pattern string) bool

Test checks if the string matches the given regular expression.

func (*Stringable) Title

func (s *Stringable) Title() *Stringable

Title converts the string to title case.

func (*Stringable) ToString

func (s *Stringable) ToString() string

ToString is an alias for String.

func (*Stringable) Trim

func (s *Stringable) Trim(characters ...string) *Stringable

Trim trims the string of the given characters.

func (*Stringable) UcFirst

func (s *Stringable) UcFirst() *Stringable

UcFirst makes the string's first character uppercase.

func (*Stringable) UcSplit

func (s *Stringable) UcSplit() []string

UcSplit splits the string by uppercase characters.

func (*Stringable) Unless

func (s *Stringable) Unless(condition bool, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

Unless applies the callback if the given condition is false.

func (*Stringable) Upper

func (s *Stringable) Upper() *Stringable

Upper converts the string to uppercase.

func (*Stringable) When

func (s *Stringable) When(condition bool, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

When applies the callback if the given condition is true.

func (*Stringable) WhenContains

func (s *Stringable) WhenContains(needle string, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenContains applies the callback if the string contains the given value.

func (*Stringable) WhenContainsAll

func (s *Stringable) WhenContainsAll(needles []string, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenContainsAll applies the callback if the string contains all given values.

func (*Stringable) WhenEmpty

func (s *Stringable) WhenEmpty(callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenEmpty applies the callback if the string is empty.

func (*Stringable) WhenEndsWith

func (s *Stringable) WhenEndsWith(needles []string, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenEndsWith applies the callback if the string ends with the given value.

func (*Stringable) WhenExactly

func (s *Stringable) WhenExactly(value string, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenExactly applies the callback if the string exactly matches the given value.

func (*Stringable) WhenIs

func (s *Stringable) WhenIs(pattern string, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenIs applies the callback if the string matches the given pattern.

func (*Stringable) WhenIsAscii

func (s *Stringable) WhenIsAscii(callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenIsAscii applies the callback if the string is ASCII.

func (*Stringable) WhenIsUlid

func (s *Stringable) WhenIsUlid(callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenIsUlid applies the callback if the string is a valid ULID.

func (*Stringable) WhenIsUuid

func (s *Stringable) WhenIsUuid(callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenIsUuid applies the callback if the string is a valid UUID.

func (*Stringable) WhenNotEmpty

func (s *Stringable) WhenNotEmpty(callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenNotEmpty applies the callback if the string is not empty.

func (*Stringable) WhenNotExactly

func (s *Stringable) WhenNotExactly(value string, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenNotExactly applies the callback if the string does not exactly match the given value.

func (*Stringable) WhenStartsWith

func (s *Stringable) WhenStartsWith(needles []string, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenStartsWith applies the callback if the string starts with the given value.

func (*Stringable) WhenTest

func (s *Stringable) WhenTest(pattern string, callback func(*Stringable) *Stringable, defaultCallback ...func(*Stringable) *Stringable) *Stringable

WhenTest applies the callback if the string matches the given regular expression.

func (*Stringable) WordCount

func (s *Stringable) WordCount() int

WordCount counts the words in the string.

func (*Stringable) WordWrap

func (s *Stringable) WordWrap(width int, breakStr ...string) *Stringable

WordWrap wraps the string at the given length.

func (*Stringable) Words

func (s *Stringable) Words(words int, end ...string) *Stringable

Words limits the number of words in the string.

Jump to

Keyboard shortcuts

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