Package: str
Utility toolkit for strings: validation, manipulation, formatting, encoding, hashing, and generation.
Repository: https://github.com/dracory/str
Install
go get github.com/dracory/str@latest
Quick Start
import "github.com/dracory/str"
ok := str.IsUUID("123e4567-e89b-12d3-a456-426614174000")
slug := str.Slugify("Hello World!", '-') // "hello-world"
Validation
str.IsEmpty("")
str.IsNotEmpty("Hi")
str.IsUUID("123e4567-e89b-12d3-a456-426614174000")
str.IsULID("01H9Z8K2P3M4N5Q6R7S8T9U0V")
str.Is("hello.txt", "*.txt")
Manipulation & Formatting
str.Between("Hello [World] Test", "[", "]") // "World"
str.Before("Hello World", "World") // "Hello "
str.After("Hello World", "Hello ") // "World"
str.LeftFrom("Hello World", 5) // "Hello"
str.RightFrom("Hello World", 5) // "World"
str.Truncate("Hello World", 8, "...") // "Hello..."
str.ToSnake("HelloWorld") // "hello_world"
str.ToCamel("hello_world") // "helloWorld"
str.UcFirst("hello") // "Hello"
str.Upper("hello") // "HELLO"
str.Words("Hello World") // ["Hello","World"]
str.WordCount("Hello World") // 2
str.Slugify("Hello World!", '-') // "hello-world"
Encoding & Hashing
str.Base64Encode("Hello World") // "SGVsbG8gV29ybGQ="
str.Base64Decode("SGVsbG8gV29ybGQ=") // "Hello World"
str.Base32ExtendedEncode("Hello World")
str.Base32ExtendedDecode("91IMOR3FCPBI41")
hash := str.MD5("Hello World")
bcrypt := str.ToBcryptHash("password")
str.BcryptHashCompare("password", bcrypt) // true
Generation
str.Random(10)
str.RandomFromGamma(10, 2.0, 1.0)
str.IntToBase32(12345) // "3RP"
str.IntToBase36(12345) // "9IX"
Notes
- Use BCrypt for passwords; MD5 only for non-security checksums.
- Complements Go stdlib (
strings
,encoding/*
) with higher-level utilities.