Pipeline-First String Toolkit for Go
Every function is func(string) string. Compose them with Pipe. Zero dependencies. 36 functions. One import.
go get github.com/schigh/str@latest
The core of str. Build reusable transformation pipelines from simple functions. Every transformer is func(string) string, and Pipe chains them left to right.
Case conversion with acronym awareness, reversal, whitespace normalization, and slug generation. All func(string) string, all pipeline-composable.
Padding, truncation, substring extraction, word wrapping, and pluralization. All return func(string) string via partial application.
Cryptographically secure random string generation with crypto/rand.
Fuzzy string matching powered by JaroWinkler similarity scoring.
String distance and similarity algorithms.
Real-world composition recipes. Build once, reuse everywhere.
Clean user input before storage
Turn any string into a URL-safe slug
Fixed-width, truncated log columns
Only shorten strings that are too long
Transform every line independently
Custom acronyms for your industry
No function panics for any input (except RandomToken on OS entropy failure). Empty in, empty out. Degenerate parameters return reasonable defaults.
| Function | Edge Input | Behavior |
|---|---|---|
Pipe() | zero functions | Identity (returns input unchanged) |
PipeIf(nil, fn) | nil predicate | No-op (passthrough) |
PipeUnless(nil, fn) | nil predicate | Always applies fn |
PipeMap(nil, j, fn) | nil split | Passthrough |
PadLeft("", N) | empty pad | Returns input unchanged |
Truncate(0, "...") | zero length | Returns empty string |
Substring(-3, 2) | negative start | Counts from end |
Wrap(0) | zero width | Returns input unchanged |
Pluralize(0, pl) | count zero | Returns plural |
RandomToken(WithLength(0)) | zero length | Returns prefix only |
| All case functions | empty string | Returns empty string |
Levenshtein("", "") | both empty | Returns 0 |
JaroWinkler("", "") | both empty | Returns 1.0 |
FuzzyMatch("", hay) | empty needle | Returns nil |