https://github.com/bmj2728/utils
a collection of utilities for Go
https://github.com/bmj2728/utils
case-conversion edit-distance go golang levenshtein-distance lorem-ipsum-generator sanitizer string-builder string-generation string-transformation strings-manipulation
Last synced: 3 months ago
JSON representation
a collection of utilities for Go
- Host: GitHub
- URL: https://github.com/bmj2728/utils
- Owner: bmj2728
- License: mit
- Created: 2025-07-12T19:11:33.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-08-12T00:56:50.000Z (8 months ago)
- Last Synced: 2025-08-12T02:33:35.423Z (8 months ago)
- Topics: case-conversion, edit-distance, go, golang, levenshtein-distance, lorem-ipsum-generator, sanitizer, string-builder, string-generation, string-transformation, strings-manipulation
- Language: Go
- Homepage: https://bmj2728.github.io/utils/
- Size: 444 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Utils - The Missing Go Utilities Package
[](https://github.com/bmj2728/utils/actions?query=workflow%3ACodeQL)
[](https://github.com/bmj2728/utils/actions)
[](https://github.com/bmj2728/utils/actions)
[](https://codecov.io/gh/bmj2728/utils)
[](https://goreportcard.com/report/github.com/bmj2728/utils)
[](https://pkg.go.dev/github.com/bmj2728/utils)
[](https://opensource.org/licenses/MIT)
[](https://golang.org/)
[](https://github.com/bmj2728/utils/releases)
> **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.
## Overview
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
## Installation π¦
### Full Library
```bash
go get github.com/bmj2728/utils
```
### Specific Components
```bash
# String utilities only
go get github.com/bmj2728/utils/pkg/strutil
```
```bash
# Version utilities only
go get github.com/bmj2728/utils/pkg/version
```
### Import Examples
```go
// Import the full string utilities package
import "github.com/bmj2728/utils/pkg/strutil"
```
```go
// Import specific utilities
import (
"github.com/bmj2728/utils/pkg/strutil"
"github.com/bmj2728/utils/pkg/version"
)
```
## Key Features β¨
### π€ String Utilities (`strutil`)
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
### π Version Utilities (`version`)
Build-time version management made simple!
- **π Version Information**: Embedded build-time version and build details
- **π Semantic Validation**: Validate and parse semantic versioning format
## Usage Guide π
### π Choose Your API Style
**Functional API** - Direct function calls for simple operations:
```go
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") // true
```
**Builder API** - Fluent chaining for complex operations:
```go
import "github.com/bmj2728/utils/pkg/strutil"
// Chain multiple operations
result, err := strutil.New("
Hello World! ").
CleanWhitespace().
SanitizeHTML().
ToLower().
Slugify(50).
Result()
// Result: "hello-world"
```
### π§Ή String Cleaning & Sanitization
```go
// Remove dangerous HTML but keep safe tags
userInput := "alert('xss')
Safe content
"
clean := strutil.SanitizeHTML(userInput) // "Safe content
"
// 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"
```
### π§ Text Transformation
```go
// 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 & Generation
```go
// 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 text
```
### π Advanced: Comparison Manager *(Optional)*
Track multiple string comparison results in one place:
```go
// 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()
```
### π Advanced: History Tracking *(Optional)*
Track transformations and revert when needed:
```go
// 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()
```
## Documentation π
For complete documentation of all available functions and their usage, please refer to the [Go Reference Documentation](https://pkg.go.dev/github.com/bmj2728/utils).
## Roadmap πΊοΈ
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
## Acknowledgements π
This project stands on the shoulders of giants! We leverage these excellent open-source libraries:
- [**go-edlib**](https://github.com/hbollon/go-edlib) - String comparison and edit distance algorithms for measuring similarity
- [**bluemonday**](https://github.com/microcosm-cc/bluemonday) - HTML sanitizer for safe HTML cleaning
- [**go-sanitize**](https://github.com/mrz1836/go-sanitize) - Powerful string cleaning and sanitization functions
- [**strcase**](https://github.com/iancoleman/strcase) - Converting strings between different case formats
- [**camelcase**](https://github.com/fatih/camelcase) - Splitting camelCase/PascalCase words into components
- [**lorelai**](https://github.com/UltiRequiem/lorelai) - Versatile lorem ipsum generator for placeholder content
- [**go-diacritics**](https://github.com/Regis24GmbH/go-diacritics) - Lightweight diacritics normalization
- [**stripansi**](https://github.com/acarl005/stripansi) - ANSI escape sequence removal for clean output
- [**google/uuid**](https://github.com/google/uuid) - Robust UUID implementation
## License
This project is licensed under the terms of the LICENSE file included in the repository.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.