Documentation
¶
Index ¶
- func AddSlashes(str string) string
- func AddSlashesCustom(str string, escapeChars string) string
- func After(str, needle string) string
- func AfterLast(str, needle string) string
- func Append(values ...string) string
- func Base32ExtendedDecode(data []byte) (text []byte, err error)
- func Base32ExtendedEncode(data []byte) (text []byte, err error)
- func Base64Decode(text []byte) (data []byte, err error)
- func Base64Encode(data []byte) (text []byte, err error)
- func BcryptHashCompare(str string, hash string) bool
- func Before(str, needle string) string
- func BeforeLast(str, needle string) string
- func Between(str string, startNeedle string, endNeedle string) (result string, found bool)
- func CharAt(str string, index int) string
- func ContainsAnyChar(str string, charset string) bool
- func ContainsOnly(str string, charset string) bool
- func CurrencySymbol(currencyCode string, htmlEntity ...bool) string
- func IntToBase32(num int) string
- func IntToBase36(num int) string
- func Is(str string, patterns ...string) bool
- func IsAscii(str string) bool
- func IsEmpty(str string) bool
- func IsMap(str string) bool
- func IsMatch(str string, patterns ...string) bool
- func IsNotEmpty(str string) bool
- func IsSlice(str string) bool
- func IsUlid(str string) bool
- func IsUuid(str string) bool
- func LeftFrom(str, needle string) string
- func LeftPad(s string, padStr string, overallLen int) string
- func MD5(text string) string
- func Random(length int) string
- func RandomFromGamma(length int, gamma string) string
- func RemovePrefix(str string, prefix string) string
- func RemoveSuffix(str string, suffix string) string
- func RightFrom(str, needle string) string
- func RightPad(s string, padStr string, overallLen int) string
- func Slugify(s string, replaceWith rune) string
- func Substr(str string, start int, length ...int) string
- func ToBcryptHash(str string) (string, error)
- func ToBytes(s string) []byte
- func ToCamel(in string) string
- func ToPrice(price float64, currencyCode string, htmlEntity ...bool) string
- func ToPriceFromString(priceStr string, currencyCode string, htmlEntity ...bool) (string, error)
- func ToPriceFromStringOrDefault(priceStr string, currencyCode string, defaultValue string, htmlEntity ...bool) string
- func ToSnake(in string) string
- func Truncate(str string, length int, ellipsis string) string
- func UcFirst(str string) string
- func UcSplit(s string) []string
- func Upper(str string) string
- func WordCount(str string) int
- func Words(str string, limit int, end ...string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSlashes ¶
AddSlashes returns a string with backslashes added before characters that need to be escaped.
These characters are: single quote (') double quote (") backslash (\)
func AddSlashesCustom ¶
AddSlashesCustom returns a string with backslashes added before characters specified in the escapeChars string.
func Base32ExtendedDecode ¶
Base32ExtendedDecode encodes binary data to base32 extended (RFC 4648) encoded text.
func Base32ExtendedEncode ¶
Base32ExtendedEncode encodes binary data to base32 extended (RFC 4648) encoded text.
func Base64Decode ¶
Base64Decode decodes base64 text to binary data.
func Base64Encode ¶
Base64Encode encodes binary data to base64 encoded text.
func BcryptHashCompare ¶
BcryptHashCompare compares the string to a bcrypt hash
func Before ¶
Before returns the substring before the first occurrence of the specified search string.
func BeforeLast ¶
BeforeLast returns the substring before the last occurrence of the specified search string.
func CharAt ¶
CharAt returns the character at the specified index.
If the specified index is negative, it is counted from the end of the string.
Business logic: 1. Convert the string to a rune slice for proper handling of UTF-8 encoding. 2. Get the length of the rune slice. 3. Handle negative indices by converting them to positive indices (e.g. -1 -> length - 1). 4. Check if the index is out of bounds. 5. If the index is out of bounds, return an empty string. 6. Return the character at the specified index.
Example:
str.CharAt("Hello World", 0) // Returns "H"
str.CharAt("Hello World", -1) // Returns "d"
str.CharAt("Hello World", 20) // Returns ""
Parameters: - str: The string to get the character from. - index: The index of the character to get.
Returns: - The character at the specified index.
func ContainsAnyChar ¶
ContainsAnyChar returns true if the string contains any of the characters in the provided charset
func ContainsOnly ¶
ContainsOnly returns true is the string contains only charcters from the specified charset
func CurrencySymbol ¶ added in v0.5.0
CurrencySymbol returns the symbol for the given ISO 4217 currency code. By default, returns the Unicode symbol. Pass true to get HTML entity instead. Returns the original currency code if not recognized. Example: CurrencySymbol("USD") returns "$" Example: CurrencySymbol("GBP", true) returns "£"
func IntToBase32 ¶
func IntToBase36 ¶
func IsNotEmpty ¶
IsNotEmpty returns true if the string is not empty.
func RandomFromGamma ¶
RandomFromGamma generates random string of specified length with the characters specified in the gamma string
func RemovePrefix ¶
func RemoveSuffix ¶
func Slugify ¶
StrSlugify replaces each run of characters which are not ASCII letters or numbers with the Replacement character, except for leading or trailing runs. Letters will be stripped of diacritical marks and lowercased. Letter or number codepoints that do not have combining marks or a lower-cased variant will be passed through unaltered.
func Substr ¶
Substr returns a substring of a given string, starting at the specified index and with a specified length. It handles UTF-8 encoded strings.
func ToBcryptHash ¶
ToBcryptHash converts the string to bcrypt hash
func ToPrice ¶ added in v0.5.0
ToPrice converts a float64 price to a formatted string with the given ISO 4217 currency code. The price is formatted to 2 decimal places. By default, returns Unicode symbol. Pass true to get HTML entity instead. Example: ToPrice(19.99, "USD") returns "$19.99" Example: ToPrice(19.99, "GBP", true) returns "£19.99"
func ToPriceFromString ¶ added in v0.5.0
ToPriceFromString converts a string price to a formatted price string with the given ISO 4217 currency code. Returns an error if the string cannot be parsed as a float. The price is formatted to 2 decimal places. By default, returns Unicode symbol. Pass true to get HTML entity instead. Example: ToPriceFromString("19.99", "USD") returns "$19.99", nil Example: ToPriceFromString("19.99", "GBP", true) returns "£19.99", nil
func ToPriceFromStringOrDefault ¶ added in v0.5.0
func ToPriceFromStringOrDefault(priceStr string, currencyCode string, defaultValue string, htmlEntity ...bool) string
ToPriceFromStringOrDefault converts a string price to a formatted price string with the given ISO 4217 currency code. Returns the defaultValue if the string cannot be parsed as a float. The price is formatted to 2 decimal places. By default, returns Unicode symbol. Pass true to get HTML entity instead. Example: ToPriceFromStringOrDefault("19.99", "USD", "n/a") returns "$19.99" Example: ToPriceFromStringOrDefault("invalid", "USD", "n/a") returns "n/a" Example: ToPriceFromStringOrDefault("19.99", "GBP", "n/a", true) returns "£19.99"
func ToSnake ¶
ToSnake convert the given string to snake case following the Golang format: acronyms are converted to lower-case and preceded by an underscore.
Types ¶
This section is empty.
Source Files
¶
- add_slashes.go
- after.go
- after_last.go
- append.go
- base32_extended_decode.go
- base32_extended_encode.go
- base64_decode.go
- base64_encode.go
- bcrypt_hash_compare.go
- before.go
- before_last.go
- between.go
- char_at.go
- contains_any_char.go
- contains_only.go
- currency_symbol.go
- functions.go
- int_to_base32.go
- int_to_base36.go
- is.go
- is_match.go
- isascii.go
- isempty.go
- ismap.go
- isnotempty.go
- isslice.go
- isulid.go
- isuuid.go
- left_from.go
- left_pad.go
- md5.go
- random.go
- random_from_gamma.go
- remove_prefix.go
- remove_suffix.go
- right_from.go
- right_pad.go
- slugify.go
- str.go
- substr.go
- to_bcrypt_hash.go
- to_bytes.go
- to_camel.go
- to_price.go
- to_price_from_string.go
- to_snake.go
- truncate.go
- uc_first.go
- uc_split.go
- upper.go
- word_count.go
- words.go