utils

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FileUtil = fileUtil{}
View Source
var StringUtil = stringUtil{}
View Source
var ToolsUtil = toolsUtil{}

Functions

func Random

func Random(length int) string

func Substr

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

Substr returns a substring of a given string, starting at the specified index and with a specified length. It handles UTF-8 encoded strings.

Types

type FileOption

type FileOption func(*fileOption)

func WithAppend

func WithAppend() FileOption

WithAppend sets the append mode for FilePutContents

func WithMode

func WithMode(mode os.FileMode) FileOption

WithMode sets the file mode for FilePutContents

type Str

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

func (*Str) After

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

After returns a new String instance with the substring after the first occurrence of the specified search string.

func (*Str) AfterLast

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

AfterLast returns the String instance with the substring after the last occurrence of the specified search string.

func (*Str) Append

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

Append appends one or more strings to the current string.

func (*Str) Basename

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

Basename returns the String instance with the basename of the current file path string, and trims the suffix based on the parameter(optional).

func (*Str) Before

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

Before returns the String instance with the substring before the first occurrence of the specified search string.

func (*Str) BeforeLast

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

BeforeLast returns the String instance with the substring before the last occurrence of the specified search string.

func (*Str) Between

func (s *Str) Between(start, end string) *Str

Between returns the String instance with the substring between the given start and end strings.

func (*Str) BetweenFirst

func (s *Str) BetweenFirst(start, end string) *Str

BetweenFirst returns the String instance with the substring between the first occurrence of the given start string and the given end string.

func (*Str) Camel

func (s *Str) Camel() *Str

Camel returns the String instance in camel case.

func (*Str) CharAt

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

CharAt returns the character at the specified index.

func (*Str) ChopEnd

func (s *Str) ChopEnd(needle string, more ...string) *Str

ChopEnd remove the given string(s) if it exists at the end of the haystack.

func (*Str) ChopStart

func (s *Str) ChopStart(needle string, more ...string) *Str

ChopStart remove the given string(s) if it exists at the start of the haystack.

func (*Str) Contains

func (s *Str) Contains(values ...string) bool

Contains returns true if the string contains the given value or any of the values.

func (*Str) ContainsAll

func (s *Str) ContainsAll(values ...string) bool

ContainsAll returns true if the string contains all of the given values.

func (*Str) Dirname

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

Dirname returns the String instance with the directory name of the current file path string.

func (*Str) EndsWith

func (s *Str) EndsWith(values ...string) bool

EndsWith returns true if the string ends with the given value or any of the values.

func (*Str) Exactly

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

Exactly returns true if the string is exactly the given value.

func (*Str) Excerpt

func (s *Str) Excerpt(phrase string, options ...excerptOption) *Str

Excerpt returns the String instance truncated to the given length.

func (*Str) Explode

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

Explode splits the string by given delimiter string.

func (*Str) Finish

func (s *Str) Finish(value string) *Str

Finish returns the String instance with the given value appended. If the given value already ends with the suffix, it will not be added twice.

func (*Str) Headline

func (s *Str) Headline() *Str

Headline returns the String instance in headline case.

func (*Str) Is

func (s *Str) Is(patterns ...string) bool

Is returns true if the string matches any of the given patterns.

func (*Str) IsAscii

func (s *Str) IsAscii() bool

IsAscii returns true if the string contains only ASCII characters.

func (*Str) IsEmpty

func (s *Str) IsEmpty() bool

IsEmpty returns true if the string is empty.

func (*Str) IsMap

func (s *Str) IsMap() bool

IsMap returns true if the string is a valid Map.

func (*Str) IsMatch

func (s *Str) IsMatch(patterns ...string) bool

IsMatch returns true if the string matches any of the given patterns.

func (*Str) IsNotEmpty

func (s *Str) IsNotEmpty() bool

IsNotEmpty returns true if the string is not empty.

func (*Str) IsSlice

func (s *Str) IsSlice() bool

IsSlice returns true if the string is a valid Slice.

func (*Str) IsUlid

func (s *Str) IsUlid() bool

IsUlid returns true if the string is a valid ULID.

func (*Str) IsUuid

func (s *Str) IsUuid() bool

IsUuid returns true if the string is a valid UUID.

func (*Str) Kebab

func (s *Str) Kebab() *Str

Kebab returns the String instance in kebab case.

func (*Str) LTrim

func (s *Str) LTrim(characters ...string) *Str

LTrim returns the String instance with the leftmost occurrence of the given value removed.

func (*Str) LcFirst

func (s *Str) LcFirst() *Str

LcFirst returns the String instance with the first character lowercased.

func (*Str) Length

func (s *Str) Length() int

Length returns the length of the string.

func (*Str) Limit

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

Limit returns the String instance truncated to the given length.

func (*Str) Lower

func (s *Str) Lower() *Str

Lower returns the String instance in lower case.

func (*Str) Mask

func (s *Str) Mask(character string, index int, length ...int) *Str

Mask returns the String instance with the given character masking the specified number of characters.

func (*Str) Match

func (s *Str) Match(pattern string) *Str

Match returns the String instance with the first occurrence of the given pattern.

func (*Str) MatchAll

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

MatchAll returns all matches for the given regular expression.

func (*Str) NewLine

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

NewLine appends one or more new lines to the current string.

func (*Str) PadBoth

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

PadBoth returns the String instance padded to the left and right sides of the given length.

func (*Str) PadLeft

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

PadLeft returns the String instance padded to the left side of the given length.

func (*Str) PadRight

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

PadRight returns the String instance padded to the right side of the given length.

func (*Str) Pipe

func (s *Str) Pipe(callback func(s string) string) *Str

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

func (*Str) Prepend

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

Prepend one or more strings to the current string.

func (*Str) RTrim

func (s *Str) RTrim(characters ...string) *Str

RTrim returns the String instance with the right occurrences of the given value removed.

func (*Str) Remove

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

Remove returns the String instance with the first occurrence of the given value removed.

func (*Str) Repeat

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

Repeat returns the String instance repeated the given number of times.

func (*Str) Replace

func (s *Str) Replace(search string, replace string, caseSensitive ...bool) *Str

Replace returns the String instance with all occurrences of the search string replaced by the given replacement string.

func (*Str) ReplaceEnd

func (s *Str) ReplaceEnd(search string, replace string) *Str

ReplaceEnd returns the String instance with the last occurrence of the given value replaced.

func (*Str) ReplaceFirst

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

ReplaceFirst returns the String instance with the first occurrence of the given value replaced.

func (*Str) ReplaceLast

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

ReplaceLast returns the String instance with the last occurrence of the given value replaced.

func (*Str) ReplaceMatches

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

ReplaceMatches returns the String instance with all occurrences of the given pattern replaced by the given replacement string.

func (*Str) ReplaceStart

func (s *Str) ReplaceStart(search string, replace string) *Str

ReplaceStart returns the String instance with the first occurrence of the given value replaced.

func (*Str) Snake

func (s *Str) Snake(delimiter ...string) *Str

Snake returns the String instance in snake case.

func (*Str) Split

func (s *Str) Split(pattern string, limit ...int) []string

Split splits the string by given pattern string.

func (*Str) Squish

func (s *Str) Squish() *Str

Squish returns the String instance with consecutive whitespace characters collapsed into a single space.

func (*Str) Start

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

Start returns the String instance with the given value prepended.

func (*Str) StartsWith

func (s *Str) StartsWith(values ...string) bool

StartsWith returns true if the string starts with the given value or any of the values.

func (*Str) String

func (s *Str) String() string

String returns the string value.

func (*Str) Studly

func (s *Str) Studly() *Str

Studly returns the String instance in studly case.

func (*Str) Substr

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

Substr returns the String instance starting at the given index with the specified length.

func (*Str) Swap

func (s *Str) Swap(replacements map[string]string) *Str

Swap replaces all occurrences of the search string with the given replacement string.

func (*Str) Tap

func (s *Str) Tap(callback func(Str)) *Str

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

func (*Str) Test

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

Test returns true if the string matches the given pattern.

func (*Str) Title

func (s *Str) Title() *Str

Title returns the String instance in title case.

func (*Str) Trim

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

Trim returns the String instance with trimmed characters from the left and right sides.

func (*Str) UcFirst

func (s *Str) UcFirst() *Str

UcFirst returns the String instance with the first character uppercased.

func (*Str) UcSplit

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

UcSplit splits the string into words using uppercase characters as the delimiter.

func (*Str) Unless

func (s *Str) Unless(callback func(*Str) bool, fallback func(*Str) *Str) *Str

Unless returns the String instance with the given fallback applied if the given condition is false.

func (*Str) Upper

func (s *Str) Upper() *Str

Upper returns the String instance in upper case.

func (*Str) When

func (s *Str) When(condition bool, callback ...func(*Str) *Str) *Str

When returns the String instance with the given callback applied if the given condition is true. If the condition is false, the fallback callback is applied (if provided).

func (*Str) WhenContains

func (s *Str) WhenContains(value string, callback ...func(*Str) *Str) *Str

WhenContains returns the String instance with the given callback applied if the string contains the given value.

func (*Str) WhenContainsAll

func (s *Str) WhenContainsAll(values []string, callback ...func(*Str) *Str) *Str

WhenContainsAll returns the String instance with the given callback applied if the string contains all the given values.

func (*Str) WhenEmpty

func (s *Str) WhenEmpty(callback ...func(*Str) *Str) *Str

WhenEmpty returns the String instance with the given callback applied if the string is empty.

func (*Str) WhenEndsWith

func (s *Str) WhenEndsWith(value []string, callback ...func(*Str) *Str) *Str

WhenEndsWith returns the String instance with the given callback applied if the string ends with the given value.

func (*Str) WhenExactly

func (s *Str) WhenExactly(value string, callback ...func(*Str) *Str) *Str

WhenExactly returns the String instance with the given callback applied if the string is exactly the given value.

func (*Str) WhenIs

func (s *Str) WhenIs(value string, callback ...func(*Str) *Str) *Str

WhenIs returns the String instance with the given callback applied if the string matches any of the given patterns.

func (*Str) WhenIsAscii

func (s *Str) WhenIsAscii(callback ...func(*Str) *Str) *Str

WhenIsAscii returns the String instance with the given callback applied if the string contains only ASCII characters.

func (*Str) WhenIsUlid

func (s *Str) WhenIsUlid(callback ...func(*Str) *Str) *Str

WhenIsUlid returns the String instance with the given callback applied if the string is a valid ULID.

func (*Str) WhenIsUuid

func (s *Str) WhenIsUuid(callback ...func(*Str) *Str) *Str

WhenIsUuid returns the String instance with the given callback applied if the string is a valid UUID.

func (*Str) WhenNotEmpty

func (s *Str) WhenNotEmpty(callback ...func(*Str) *Str) *Str

WhenNotEmpty returns the String instance with the given callback applied if the string is not empty.

func (*Str) WhenNotExactly

func (s *Str) WhenNotExactly(value string, callback ...func(*Str) *Str) *Str

WhenNotExactly returns the String instance with the given callback applied if the string is not exactly the given value.

func (*Str) WhenStartsWith

func (s *Str) WhenStartsWith(value []string, callback ...func(*Str) *Str) *Str

WhenStartsWith returns the String instance with the given callback applied if the string starts with the given value.

func (*Str) WhenTest

func (s *Str) WhenTest(pattern string, callback ...func(*Str) *Str) *Str

WhenTest returns the String instance with the given callback applied if the string matches the given pattern.

func (*Str) WordCount

func (s *Str) WordCount() int

WordCount returns the number of words in the string.

func (*Str) Words

func (s *Str) Words(limit int, end ...string) *Str

Words return the String instance truncated to the given number of words.

Jump to

Keyboard shortcuts

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