Documentation
¶
Index ¶
- func Contains(text, search string) bool
- func CountOccurrences(text, search string) int
- func ParseKeyValue(input string, delimiters ...string) (value string, err error)
- func Split(data, separator string) (result []string)
- type Text
- func (t *Text) CamelCaseLower() *Text
- func (t *Text) CamelCaseUpper() *Text
- func (t *Text) Capitalize() *Text
- func (t *Text) RemoveTilde() *Text
- func (t *Text) Repeat(n int) *Text
- func (t *Text) Replace(old, newStr string) *Text
- func (t *Text) String() string
- func (t *Text) ToLower() *Text
- func (t *Text) ToSnakeCaseLower(sep ...string) *Text
- func (t *Text) ToSnakeCaseUpper(sep ...string) *Text
- func (t *Text) ToUpper() *Text
- func (t *Text) Trim() *Text
- func (t *Text) TrimPrefix(prefix string) *Text
- func (t *Text) TrimSuffix(suffix string) *Text
- func (t *Text) Truncate(maxWidth int, reservedChars int) *Text
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶ added in v0.0.8
Contains checks if the string 'search' is present in 'text' Returns true if found, false otherwise This matches the behavior of the standard library strings.Contains
func CountOccurrences ¶ added in v0.0.8
CountOccurrences checks how many times the string 'search' is present in 'text' eg: "hello world" with search "world" will return 1
func ParseKeyValue ¶ added in v0.0.10
ParseKeyValue extracts the value part from a "key:value" formatted string. By default, it uses ":" as the delimiter but accepts an optional custom delimiter. The function returns the value part and an error (nil if successful).
Examples:
value, err := ParseKeyValue("name:John") // value = "John", err = nil value, err := ParseKeyValue("data=123", "=") // value = "123", err = nil value, err := ParseKeyValue("invalid-string") // value = "", err = error containing "delimiter ':' not found in string invalid-string"
Types ¶
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text struct to store the content of the text
func Convert ¶
initialize the text struct with any type of value supports string, int, float, bool and their variants
func (*Text) CamelCaseLower ¶
converts text to camelCase (first word lowercase) eg: "Hello world" -> "helloWorld"
func (*Text) CamelCaseUpper ¶
converts text to PascalCase (all words capitalized) eg: "hello world" -> "HelloWorld"
func (*Text) Capitalize ¶ added in v0.0.11
Capitalize transforms the first letter of each word to uppercase and the rest to lowercase. For example: "hello world" -> "Hello World"
func (*Text) Repeat ¶ added in v0.0.13
Repeat returns the string s repeated n times. If n is less than or equal to zero, or if s is empty, it returns an empty string. eg: Convert("abc").Repeat(3) => "abcabcabc"
func (*Text) Replace ¶ added in v0.0.7
Replace replaces all occurrences of old with new in the text content eg: "hello world" with old "world" and new "universe" will return "hello universe"
func (*Text) ToSnakeCaseLower ¶
snakeCase converts a string to snake_case format with optional separator. If no separator is provided, underscore "_" is used as default. Example:
Input: "camelCase" -> Output: "camel_case" Input: "PascalCase", "-" -> Output: "pascal-case" Input: "APIResponse" -> Output: "api_response" Input: "user123Name", "." -> Output: "user123.name"
ToSnakeCaseLower converts text to snake_case format
func (*Text) ToSnakeCaseUpper ¶
ToSnakeCaseUpper converts text to Snake_Case format
func (*Text) Trim ¶ added in v0.0.7
Trim removes spaces at the beginning and end of the text content eg: " hello world " will return "hello world"
func (*Text) TrimPrefix ¶ added in v0.0.9
TrimPrefix removes the specified prefix from the text content if it exists eg: "prefix-hello" with prefix "prefix-" will return "hello"
func (*Text) TrimSuffix ¶ added in v0.0.7
TrimSuffix removes the specified suffix from the text content if it exists eg: "hello.txt" with suffix ".txt" will return "hello"
func (*Text) Truncate ¶ added in v0.0.13
Truncate truncates a text so that it has exactly the specified width. If the text is longer, it truncates it and adds "..." if there is space. If the text is shorter, it pads it with spaces until the width is reached. The reservedChars parameter indicates how many characters should be reserved for suffixes. eg: Convert("Hello, World!").Truncate(10, 3) => "Hel..."