https://github.com/murat/go-utils
This package includes various utilities and extensions for your Go code.
https://github.com/murat/go-utils
golang golang-package golang-utils utilities
Last synced: 3 months ago
JSON representation
This package includes various utilities and extensions for your Go code.
- Host: GitHub
- URL: https://github.com/murat/go-utils
- Owner: murat
- License: mit
- Created: 2022-05-08T00:04:12.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-05-25T21:00:58.000Z (about 3 years ago)
- Last Synced: 2025-01-10T04:49:49.828Z (5 months ago)
- Topics: golang, golang-package, golang-utils, utilities
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go utilities

This package includes various utilities and extensions for your Go code.
Inspired by [lodash](https://lodash.com)
## Install
```shell
go get github.com/murat/go-utils@master
```## Usage
### String extensions
```go
package mainimport (
"fmt""github.com/murat/go-utils/strings"
)func main() {
// Capitalize
fmt.Println(strings.Capitalize("hello world")) // Hello World
// CamelCase
fmt.Println(strings.ToCamelCase("hello world")) // helloWorld
// SnakeCase
fmt.Println(strings.ToSnakeCase("hello world")) // hello_world
// Deburr
fmt.Println(strings.Deburr("éàèù")) // eaeu
// KebabCase
fmt.Println(strings.ToKebabCase("hello world")) // hello-world
// Paddings
fmt.Println("|" + strings.Pad("hello", 20) + "|") // | hello |
fmt.Println(strings.PadWith("hello", 20, "-")) // |-------hello--------|
fmt.Println(strings.PadLeft("hello", 20)) // | hello|
fmt.Println(strings.PadLeftWith("hello", 20, "-")) // |---------------hello|
fmt.Println(strings.PadRight("hello", 20)) // |hello |
fmt.Println(strings.PadRightWith("hello", 20, "-")) // |hello---------------|
// Slices (>1.18 needs generics)
fmt.Println(slices.Contains([]interface{}{"a", "b", "c"}, "b")) // true
fmt.Println(slices.Contains([]interface{}{"a", "b", "c"}, "x")) // false
fmt.Println(slices.Shuffle([]string{"a", "b", "c"})) // [c b a]
fmt.Println(slices.Shuffle([]int{1, 2, 3})) // [2 3 1]
fmt.Println(slices.Shuffle([]interface{}{1, "hello", 3})) // [hello 3 1]
}
```## Contribute
All contributors are welcome to contribute to this project.
Cheers :beer: