From ae673ddf7fe83db306cfa36ca10212c452101d7f Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Sun, 28 Jan 2024 08:34:22 -0800 Subject: [PATCH] add stringsext.Join (#44) --- CHANGELOG.md | 7 ++++++- README.md | 2 +- strings/join.go | 10 ++++++++++ strings/join_test.go | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 strings/join.go create mode 100644 strings/join_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 953b533..5affeac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [5.26.0] - 2024-01-28 +### Added +- `stringsext.Join` a more ergonomic way to join strings with a separator when you don't have a slice of strings. + ## [5.25.0] - 2024-01-22 ### Added - Add additional `Option.Scan` type support for `sql.Scanner` interface of Uint, Uint16, Uint32, Uint64, Int, Int, Int8, Float32, []byte, json.RawValue. @@ -94,7 +98,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `timext.NanoTime` for fast low level monotonic time with nanosecond precision. -[Unreleased]: https://github.com/go-playground/pkg/compare/v5.25.0...HEAD +[Unreleased]: https://github.com/go-playground/pkg/compare/v5.26.0...HEAD +[5.26.0]: https://github.com/go-playground/pkg/compare/v5.25.0..v5.26.0 [5.25.0]: https://github.com/go-playground/pkg/compare/v5.24.0..v5.25.0 [5.24.0]: https://github.com/go-playground/pkg/compare/v5.23.0..v5.24.0 [5.23.0]: https://github.com/go-playground/pkg/compare/v5.22.0..v5.23.0 diff --git a/README.md b/README.md index b9deb2c..a4273be 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pkg -![Project status](https://img.shields.io/badge/version-5.25.0-green.svg) +![Project status](https://img.shields.io/badge/version-5.26.0-green.svg) [![Lint & Test](https://github.com/go-playground/pkg/actions/workflows/go.yml/badge.svg)](https://github.com/go-playground/pkg/actions/workflows/go.yml) [![Coverage Status](https://coveralls.io/repos/github/go-playground/pkg/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pkg?branch=master) [![GoDoc](https://godoc.org/github.com/go-playground/pkg?status.svg)](https://pkg.go.dev/mod/github.com/go-playground/pkg/v5) diff --git a/strings/join.go b/strings/join.go new file mode 100644 index 0000000..611eb10 --- /dev/null +++ b/strings/join.go @@ -0,0 +1,10 @@ +package stringsext + +import "strings" + +// Join is a wrapper around strings.Join with a more ergonomic interface when you don't already have a slice of strings. +// +// Join concatenates the variadic elements placing the separator string between each element. +func Join(sep string, s ...string) string { + return strings.Join(s, sep) +} diff --git a/strings/join_test.go b/strings/join_test.go new file mode 100644 index 0000000..f89e688 --- /dev/null +++ b/strings/join_test.go @@ -0,0 +1,14 @@ +package stringsext + +import ( + "strings" + "testing" +) + +func TestJoin(t *testing.T) { + s1, s2, s3 := "a", "b", "c" + arr := []string{s1, s2, s3} + if strings.Join(arr, ",") != Join(",", s1, s2, s3) { + t.Errorf("Join failed") + } +}