stringutils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package stringutils provides string manipulation utilities. Started as a simple collection, grew over time as I needed more functions. Now it's basically my kitchen sink of string operations lol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string) string

CamelCase converts string to camelCase Because JavaScript developers ruined me

func Capitalize

func Capitalize(s string) string

Capitalize converts first letter of each word to uppercase Works pretty well for most cases I've tried Probably breaks on some edge cases but ¯\_(ツ)_/¯

func CharCount

func CharCount(s string) int

CharCount counts characters (runes) in string - handles Unicode properly

func Contains

func Contains(s string, substrings ...string) bool

Contains checks if s contains any of the substrings (variadic version)

func ContainsAll

func ContainsAll(s string, substrings []string) bool

ContainsAll checks if s contains all of the substrings

func ContainsAny

func ContainsAny(s string, substrings []string) bool

ContainsAny checks if s contains any of the substrings

func IsEmpty

func IsEmpty(s string) bool

IsEmpty checks if a string is empty or only whitespace. TODO: maybe rename this to be consistent with IsEmptyString? But then again, changing APIs is a pain...

func IsEmptyString

func IsEmptyString(s string) bool

IsEmptyString is an alias for IsEmpty - added for consistency Yes, I know having both is redundant but tests expected it

func IsNotEmpty

func IsNotEmpty(s string) bool

IsNotEmpty checks if string has content (opposite of IsEmpty) Because sometimes double negatives hurt my brain

func KebabCase

func KebabCase(s string) string

KebabCase converts string to kebab-case CSS class names love this

func LineCount

func LineCount(s string) int

LineCount counts lines in string

func Pad

func Pad(s string, length int, padChar rune, left bool) string

Pad pads string to specified length with padChar. Internal function that does the actual work

func PadLeft

func PadLeft(s string, length int, padChar rune) string

PadLeft pads string on the left to reach target length

func PadRight

func PadRight(s string, length int, padChar rune) string

PadRight pads string on the right to reach target length

func PascalCase

func PascalCase(s string) string

PascalCase converts string to PascalCase The C# in me demands this exists

func Quote

func Quote(s string) string

Quote wraps string in double quotes, escaping internal quotes Why reinvent the wheel when strconv.Quote exists? Good question!

func RandomString

func RandomString(length int, charset string) (string, error)

RandomString generates a random string with given charset. Default charset includes alphanumeric if none provided Fun fact: spent way too much time making this "cryptographically secure" Fun fact: spent way too much time making this "cryptographically secure"

func Reverse

func Reverse(s string) string

Reverse reverses a string preserving Unicode characters. Had to look up how to handle Unicode properly - runes are tricky!

func Slug

func Slug(s string) string

Slug creates a URL-friendly slug from a string Converts to lowercase and replaces non-alphanumeric with hyphens Perfect for blog post URLs (if I ever finish that blog)

func SnakeCase

func SnakeCase(s string) string

SnakeCase converts string to snake_case Python developers, this one's for you

func ToCase

func ToCase(s, format string) string

ToCase converts string to specified case format. This was my attempt at a unified interface but maybe individual functions are clearer Keeping it for backwards compatibility even though it feels over-engineered

func Truncate

func Truncate(s string, maxLength int, suffix string) string

Truncate truncates string to maxLength, adding suffix if truncated.

func Unquote

func Unquote(s string) string

Unquote removes surrounding quotes if present This one I actually had to write myself because strconv.Unquote is picky

func WordCount

func WordCount(s string) int

WordCount counts words in a string - splits on whitespace

Types

This section is empty.

Jump to

Keyboard shortcuts

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