Status: v0.3.1 πβStable API with comprehensive testing
A comprehensive collection of utility packages for Go, designed to fill the gaps in the standard library and provide a consistent, well-tested set of tools for common programming tasks.
This project aims to provide a set of utility packages that follow these principles:
- Simple: Easy to understand and use
- Consistent: Predictable APIs across all packages
- Well-tested: High test coverage and robust error handling
- Performant: Optimized for speed and memory usage
- Modular: Use only what you need
go get github.com/bmj2728/utils# String utilities only
go get github.com/bmj2728/utils/pkg/strutil# Version utilities only
go get github.com/bmj2728/utils/pkg/version// Import the full string utilities package
import "github.com/bmj2728/utils/pkg/strutil"// Import specific utilities
import (
"github.com/bmj2728/utils/pkg/strutil"
"github.com/bmj2728/utils/pkg/version"
)The heart of the library - comprehensive string manipulation with dual APIs!
- π― Dual API Design: Choose your style - functional for simplicity, builder for chaining
- π§Ή Sanitization & Cleaning: HTML sanitization, whitespace normalization, character filtering
- π String Comparison: Levenshtein, Jaro-Winkler, LCS, and more algorithms
- π Comparison Manager: Track and organize multiple comparison results (optional)
- π History Tracking: Revert transformations with full history (optional)
- π§ Text Transformation: Case conversion, slug generation, truncation, padding
- β Validation: Email, URL, numeric, and custom pattern validation
- π² Generation: Lorem ipsum text, emails, and placeholder content
Build-time version management made simple!
- π Version Information: Embedded build-time version and build details
- π Semantic Validation: Validate and parse semantic versioning format
Functional API - Direct function calls for simple operations:
import "github.com/bmj2728/utils/pkg/strutil"
// Simple operations
cleaned := strutil.CleanWhitespace(" hello world ") // "hello world"
slug := strutil.Slugify("Hello World!", 20) // "hello-world"
isValid := strutil.IsEmail("user@example.com") // trueBuilder API - Fluent chaining for complex operations:
import "github.com/bmj2728/utils/pkg/strutil"
// Chain multiple operations
result, err := strutil.New(" <div>Hello World!</div> ").
CleanWhitespace().
SanitizeHTML().
ToLower().
Slugify(50).
Result()
// Result: "hello-world"// Remove dangerous HTML but keep safe tags
userInput := "<script>alert('xss')</script><p>Safe content</p>"
clean := strutil.SanitizeHTML(userInput) // "<p>Safe content</p>"
// Clean whitespace and normalize
messy := " \t hello world \n "
tidy := strutil.CleanWhitespace(messy) // "hello world"
// Remove non-printable characters
withControl := "hello\x00\x01world"
printable := strutil.RemoveNonPrintable(withControl) // "helloworld"// Case conversions
text := "hello_world"
camel := strutil.ToCamelCase(text) // "helloWorld"
pascal := strutil.ToPascalCase(text) // "HelloWorld"
kebab := strutil.ToKebabCase(text) // "hello-world"
// String manipulation
original := "Hello World"
prepended := strutil.Prepend(original, "*********") // "*********Hello World"
truncated := strutil.Truncate(original, 5, "...") // "Hello..."// Validation
strutil.IsEmail("test@example.com") // true
strutil.IsURL("https://example.com") // true
strutil.IsNumeric("12345", true) // true
// Lorem ipsum generation
sentence := strutil.LoremSentence() // "Dapibus dictum sollicitudin congue dignissim hendrerit massa commodo."
email := strutil.LoremEmail() // "lorem@ipsum.amet"
paragraph := strutil.LoremParagraph() // Full paragraph of lorem textTrack multiple string comparison results in one place:
// Create a builder with comparison manager
manager := strutil.New("hello world").
WithComparisonManager().
LevenshteinDistance("hello there").
Similarity("hello there", strutil.JaroWinkler).
LCSBacktrack("hello there").
GetComparisonManager()
// Accessing results
levDist, err := manager.GetComparisonResult(strutil.LevDist, "hello there").(*strutil.ComparisonResultInt).
GetScoreInt()
sim, err := manager.GetSimilarityResult(strutil.JaroWinkler, "hello there").GetScore()
lcs := manager.GetLCSResult(strutil.LCSBacktrackWord, "hello there").GetResult()[0]
// Get all results for analysis
allComparisons := manager.GetComparisonResultsMap()
allSimilarities := manager.GetSimilarityResultsMap()Track transformations and revert when needed:
// Enable history tracking
result, err := strutil.New(" Hello WORLD! ").
WithHistory(10). // Track history, rotating after the tenth change
Trim(). // "Hello WORLD!"
ToLower(). // "hello world!"
ToTitle(). // "Hello World!"
Slugify(20). // "hello-world"
Result()
// Access transformation history
history := strutil.New(" Hello WORLD! ").
WithHistory(10).
Trim().
ToLower().
GetHistory()
fmt.Println(history.GetAll()) // [" Hello WORLD! ", "Hello WORLD!", "hello world!"]
// Revert to previous states
reverted, err := strutil.New(" Hello WORLD! ").
WithHistory(10).
CleanWhitespace().
ToLower().
RevertToPrevious(). // Back to "Hello WORLD!"
Result()For complete documentation of all available functions and their usage, please refer to the Go Reference Documentation.
Exciting utilities coming in future releases:
- π fileoputils - Safe file operations leveraging Go 1.24+ features
- ποΈ dbutils - Database utilities and connection management
- π sliceutils - Advanced slice manipulation and algorithms
- π’ floatutils - Floating-point utilities and math helpers
- π shellutils - Shell command execution and process management
- π netutils - Network utilities and HTTP helpers
This project stands on the shoulders of giants! We leverage these excellent open-source libraries:
- go-edlib - String comparison and edit distance algorithms for measuring similarity
- bluemonday - HTML sanitizer for safe HTML cleaning
- go-sanitize - Powerful string cleaning and sanitization functions
- strcase - Converting strings between different case formats
- camelcase - Splitting camelCase/PascalCase words into components
- lorelai - Versatile lorem ipsum generator for placeholder content
- go-diacritics - Lightweight diacritics normalization
- stripansi - ANSI escape sequence removal for clean output
- google/uuid - Robust UUID implementation
This project is licensed under the terms of the LICENSE file included in the repository.
Contributions are welcome! Please feel free to submit a Pull Request.
