strings

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 12 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StringsRegistry

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

func NewRegistry

func NewRegistry() *StringsRegistry

NewRegistry creates a new instance of strings registry.

func (*StringsRegistry) Capitalize added in v0.6.0

func (sr *StringsRegistry) Capitalize(value string) string

Capitalize capitalizes the first letter of 'value'.

Parameters:

value string - the string to capitalize.

Returns:

string - the string with the first letter capitalized.

For an example of this function in a Go template, refer to Sprout Documentation: capitalize.

func (*StringsRegistry) Contains

func (sr *StringsRegistry) Contains(substring string, value string) bool

Contains checks if 'str' contains the 'substring'.

Parameters:

substring string - the substring to search for.
value string - the string to search within.

Returns:

bool - true if 'str' contains 'substring', false otherwise.

For an example of this function in a Go template, refer to Sprout Documentation: contains.

func (*StringsRegistry) Ellipsis

func (sr *StringsRegistry) Ellipsis(maxWidth int, value string) string

Ellipsis truncates 'str' to 'maxWidth' and appends an ellipsis if the string is longer than 'maxWidth'.

Parameters:

maxWidth int - the maximum width of the string including the ellipsis.
value string - the string to truncate.

Returns:

string - the possibly truncated string with an ellipsis.

For an example of this function in a Go template, refer to Sprout Documentation: ellipsis.

func (*StringsRegistry) EllipsisBoth

func (sr *StringsRegistry) EllipsisBoth(offset int, maxWidth int, value string) string

EllipsisBoth truncates 'str' from both ends, preserving the middle part of the string and appending ellipses to both ends if needed.

Parameters:

offset int - starting position for preserving text.
maxWidth int - the total maximum width including ellipses.
value string - the string to truncate.

Returns:

string - the truncated string with ellipses on both ends.

For an example of this function in a Go template, refer to Sprout Documentation: ellipsisBoth.

func (*StringsRegistry) HasPrefix

func (sr *StringsRegistry) HasPrefix(prefix string, value string) bool

HasPrefix checks if 'str' starts with the specified 'prefix'.

Parameters:

prefix string - the prefix to check.
value string - the string to check.

Returns:

bool - true if 'str' starts with 'prefix', false otherwise.

For an example of this function in a Go template, refer to Sprout Documentation: hasPrefix.

func (*StringsRegistry) HasSuffix

func (sr *StringsRegistry) HasSuffix(suffix string, value string) bool

HasSuffix checks if 'str' ends with the specified 'suffix'.

Parameters:

suffix string - the suffix to check.
value string - the string to check.

Returns:

bool - true if 'str' ends with 'suffix', false otherwise.

For an example of this function in a Go template, refer to Sprout Documentation: hasSuffix.

func (*StringsRegistry) Indent

func (sr *StringsRegistry) Indent(spaces int, value string) string

Indent adds spaces to the beginning of each line in 'value'.

Parameters:

spaces int - the number of spaces to add.
value string - the string to indent.

Returns:

string - the indented string.

For an example of this function in a Go template, refer to Sprout Documentation: indent.

func (*StringsRegistry) Initials

func (sr *StringsRegistry) Initials(value string) string

Initials extracts the initials from 'str', using optional 'delimiters' to determine word boundaries.

Parameters:

value string - the string from which to extract initials.

Returns:

string - the initials of the words in 'str'.

For an example of this function in a Go template, refer to Sprout Documentation: initials.

func (*StringsRegistry) Join

func (sr *StringsRegistry) Join(sep string, value any) string

Join concatenates the elements of a slice into a single string separated by 'sep'. The slice is extracted from 'v', which can be any slice input. The function uses 'Strslice' to convert 'v' to a slice of strings if necessary.

Parameters:

sep string - the separator string.
value any - the slice to join, can be of any slice type.

Returns:

string - the concatenated string.

For an example of this function in a Go template, refer to Sprout Documentation: join.

func (*StringsRegistry) LinkHandler

func (sr *StringsRegistry) LinkHandler(fh sprout.Handler) error

LinkHandler links the handler to the registry at runtime.

func (*StringsRegistry) Nindent

func (sr *StringsRegistry) Nindent(spaces int, value string) string

func (*StringsRegistry) Nospace

func (sr *StringsRegistry) Nospace(value string) string

Nospace removes all whitespace characters from the provided string. It uses the unicode package to identify whitespace runes and removes them.

Parameters:

value string - the string from which to remove whitespace.

Returns:

string - the modified string with all whitespace characters removed.

For an example of this function in a Go template, refer to Sprout Documentation: nospace.

func (*StringsRegistry) Plural

func (sr *StringsRegistry) Plural(one, many string, count int) string

Plural returns 'one' if 'count' is 1, otherwise it returns 'many'.

Parameters:

one string - the string to return if 'count' is 1.
many string - the string to return if 'count' is not 1.
count int - the number used to determine which string to return.

Returns:

string - either 'one' or 'many' based on 'count'.

For an example of this function in a Go template, refer to Sprout Documentation: plural.

func (*StringsRegistry) Quote

func (sr *StringsRegistry) Quote(values ...any) string

Quote wraps each element in 'values' with double quotes and separates them with spaces.

Parameters:

values ...any - the elements to be quoted.

Returns:

string - a single string with each element double quoted.

For an example of this function in a Go template, refer to Sprout Documentation: quote.

func (*StringsRegistry) RegisterFunctions

func (sr *StringsRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error

RegisterFunctions registers all functions of the registry.

func (*StringsRegistry) Repeat

func (sr *StringsRegistry) Repeat(count int, value string) string

Repeat repeats the string 'str' for 'count' times.

Parameters:

count int - the number of times to repeat.
value string - the string to repeat.

Returns:

string - the repeated string.

For an example of this function in a Go template, refer to Sprout Documentation: repeat.

func (*StringsRegistry) Replace

func (sr *StringsRegistry) Replace(old, new, value string) string

Replace replaces all occurrences of 'old' in 'src' with 'new'.

Parameters:

old string - the substring to be replaced.
new string - the substring to replace with.
value string - the source string where replacements take place.

Returns:

string - the modified string after all replacements.

For an example of this function in a Go template, refer to Sprout Documentation: replace.

func (*StringsRegistry) Seq

func (sr *StringsRegistry) Seq(params ...int) string

Seq generates a sequence of numbers as a string. It can take 0, 1, 2, or 3 integers as parameters defining the start, end, and step of the sequence. NOTE: This function works similarly to the seq command in Unix systems.

Parameters:

params ...int - sequence parameters (start, step, end).

Returns:

string - a space-separated string of numbers in the sequence.

For an example of this function in a Go template, refer to Sprout Documentation: seq.

func (*StringsRegistry) Shuffle

func (sr *StringsRegistry) Shuffle(value string) string

Shuffle randomly rearranges the characters in 'str'.

Parameters:

value string - the string to shuffle.

Returns:

string - the shuffled string.

For an example of this function in a Go template, refer to Sprout Documentation: shuffle.

func (*StringsRegistry) Split

func (sr *StringsRegistry) Split(sep, value string) map[string]string

Split divides 'value' into a map of string parts using 'sep' as the separator.

Parameters:

sep string - the separator string.
value string - the original string to split.

Returns:

map[string]string - a map of the split parts.

For an example of this function in a Go template, refer to Sprout Documentation: split.

func (*StringsRegistry) Splitn

func (sr *StringsRegistry) Splitn(sep string, n int, value string) map[string]string

Splitn divides 'value' into a map of string parts using 'sep' as the separator up to 'n' parts.

Parameters:

sep string - the separator string.
n int - the maximum number of substrings to return.
value string - the original string to split.

Returns:

map[string]string - a map of the split parts.

For an example of this function in a Go template, refer to Sprout Documentation: splitn.

func (*StringsRegistry) Squote

func (sr *StringsRegistry) Squote(values ...any) string

Squote wraps each element in 'values' with single quotes and separates them with spaces.

Parameters:

values ...any - the elements to be single quoted.

Returns:

string - a single string with each element single quoted.

For an example of this function in a Go template, refer to Sprout Documentation: squote.

func (*StringsRegistry) Substring

func (sr *StringsRegistry) Substring(start, end int, value string) string

Substring extracts a substring from 's' starting at 'start' and ending at 'end'. Negative values for 'start' or 'end' are interpreted as positions from the end of the string.

Parameters:

start int - the starting index.
end int - the ending index, exclusive.
value string - the source string.

Returns:

string - the extracted substring.

For an example of this function in a Go template, refer to Sprout Documentation: substr.

func (*StringsRegistry) SwapCase

func (sr *StringsRegistry) SwapCase(value string) string

SwapCase switches the case of each letter in 'value'. Lowercase letters become uppercase and vice versa.

Parameters:

value string - the string to convert.

Returns:

string - the string with each character's case switched.

For an example of this function in a Go template, refer to Sprout Documentation: swapCase.

func (*StringsRegistry) ToCamelCase

func (sr *StringsRegistry) ToCamelCase(value string) string

ToCamelCase converts a string to camelCase.

Parameters:

value string - the string to convert.

Returns:

string - the string converted to camelCase.

For an example of this function in a Go template, refer to Sprout Documentation: toCamelCase.

func (*StringsRegistry) ToConstantCase

func (sr *StringsRegistry) ToConstantCase(value string) string

ToConstantCase converts a string to CONSTANT_CASE.

Parameters:

value string - the string to convert.

Returns:

For an example of this function in a Go template, refer to Sprout Documentation: toConstantCase.

func (*StringsRegistry) ToDotCase

func (sr *StringsRegistry) ToDotCase(value string) string

ToDotCase converts a string to dot.case.

Parameters:

value string - the string to convert.

Returns:

string - the string converted to dot.case.

For an example of this function in a Go template, refer to Sprout Documentation: toDotCase.

func (*StringsRegistry) ToKebabCase

func (sr *StringsRegistry) ToKebabCase(value string) string

ToKebabCase converts a string to kebab-case.

Parameters:

value string - the string to convert.

Returns:

string - the string converted to kebab-case.

Example:

{{ "hello world" | toKebabCase }} // Output: "hello-world"

func (*StringsRegistry) ToLower

func (sr *StringsRegistry) ToLower(value string) string

ToLower converts all characters in the provided string to lowercase.

Parameters:

value string - the string to convert.

Returns:

string - the lowercase version of the input string.

For an example of this function in a Go template, refer to Sprout Documentation: toLower.

func (*StringsRegistry) ToPascalCase

func (sr *StringsRegistry) ToPascalCase(value string) string

ToPascalCase converts a string to PascalCase.

Parameters:

value string - the string to convert.

Returns:

string - the string converted to PascalCase.

For an example of this function in a Go template, refer to Sprout Documentation: toPascalCase.

func (*StringsRegistry) ToPathCase

func (sr *StringsRegistry) ToPathCase(value string) string

ToPathCase converts a string to path/case.

Parameters:

value string - the string to convert.

Returns:

string - the string converted to path/case.

For an example of this function in a Go template, refer to Sprout Documentation: toPathCase.

func (*StringsRegistry) ToSnakeCase

func (sr *StringsRegistry) ToSnakeCase(value string) string

ToSnakeCase converts a string to snake_case.

Parameters:

value string - the string to convert.

Returns:

string - the string converted to snake_case.

For an example of this function in a Go template, refer to Sprout Documentation: toSnakeCase.

func (*StringsRegistry) ToTitleCase

func (sr *StringsRegistry) ToTitleCase(value string) string

ToTitleCase converts a string to Title Case.

Parameters:

value string - the string to convert.

Returns:

string - the string converted to Title Case.

For an example of this function in a Go template, refer to Sprout Documentation: toTitleCase.

func (*StringsRegistry) ToUpper

func (sr *StringsRegistry) ToUpper(value string) string

ToUpper converts all characters in the provided string to uppercase.

Parameters:

value string - the string to convert.

Returns:

string - the uppercase version of the input string.

For an example of this function in a Go template, refer to Sprout Documentation: toUpper.

func (*StringsRegistry) Trim

func (sr *StringsRegistry) Trim(value string) string

Trim removes leading and trailing whitespace from the string.

Parameters:

value string - the string to trim.

Returns:

string - the trimmed string.

For an example of this function in a Go template, refer to Sprout Documentation: trim.

func (*StringsRegistry) TrimAll

func (sr *StringsRegistry) TrimAll(cutset string, value string) string

TrimAll removes all occurrences of any characters in 'cutset' from both the beginning and the end of 'str'.

Parameters:

cutset string - a string of characters to remove from the string.
value string - the string to trim.

Returns:

string - the string with specified characters removed.

For an example of this function in a Go template, refer to Sprout Documentation: trimAll.

func (*StringsRegistry) TrimPrefix

func (sr *StringsRegistry) TrimPrefix(prefix string, value string) string

TrimPrefix removes the 'prefix' from the start of 'str' if present.

Parameters:

prefix string - the prefix to remove.
value string - the string to trim.

Returns:

string - the string with the prefix removed if it was present.

For an example of this function in a Go template, refer to Sprout Documentation: trimPrefix.

func (*StringsRegistry) TrimSuffix

func (sr *StringsRegistry) TrimSuffix(suffix string, value string) string

TrimSuffix removes the 'suffix' from the end of 'str' if present.

Parameters:

suffix string - the suffix to remove.
value string - the string to trim.

Returns:

string - the string with the suffix removed if it was present.

For an example of this function in a Go template, refer to Sprout Documentation: trimSuffix.

func (*StringsRegistry) Trunc

func (sr *StringsRegistry) Trunc(count int, value string) string

Trunc truncates 's' to a maximum length 'count'. If 'count' is negative, it removes '-count' characters from the beginning of the string.

Parameters:

count int - the number of characters to keep. Negative values indicate truncation
            from the beginning.
value string - the string to truncate.

Returns:

string - the truncated string.

For an example of this function in a Go template, refer to Sprout Documentation: trunc.

func (*StringsRegistry) UID added in v1.0.0

func (sr *StringsRegistry) UID() string

UID returns the unique identifier of the registry.

func (*StringsRegistry) Uncapitalize added in v0.6.0

func (sr *StringsRegistry) Uncapitalize(value string) string

Uncapitalize converts the first letter of 'value' to lowercase.

Parameters:

value string - the string to uncapitalize.

Returns:

string - the string with the first letter in lowercase.

For an example of this function in a Go template, refer to Sprout Documentation: uncapitalize.

func (*StringsRegistry) Untitle

func (sr *StringsRegistry) Untitle(value string) string

Untitle converts the first letter of each word in 'str' to lowercase.

Parameters:

value string - the string to be converted.

Returns:

string - the converted string with each word starting in lowercase.

For an example of this function in a Go template, refer to Sprout Documentation: untitle.

func (*StringsRegistry) Wrap

func (sr *StringsRegistry) Wrap(length int, value string) string

Wrap breaks 'value' into lines with a maximum length of 'length'. It ensures that words are not split across lines unless necessary.

Parameters:

length int - the maximum length of each line.
value string - the string to be wrapped.

Returns:

string - the wrapped string using newline characters to separate lines.

For an example of this function in a Go template, refer to Sprout Documentation: wrap.

func (*StringsRegistry) WrapWith

func (sr *StringsRegistry) WrapWith(length int, newLineCharacter string, value string) string

WrapWith breaks 'value' into lines of maximum 'length', using 'newLineCharacter' to separate lines. It wraps words only when they exceed the line length.

Parameters:

length int - the maximum line length.
newLineCharacter string - the character(s) used to denote new lines.
value string - the string to wrap.

Returns:

string - the wrapped string.

For an example of this function in a Go template, refer to Sprout Documentation: wrapWith.

Jump to

Keyboard shortcuts

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