https://github.com/oalders/go-joined
Golang library which provides functions for joining lists into natural language strings.
https://github.com/oalders/go-joined
golang join strings
Last synced: about 1 year ago
JSON representation
Golang library which provides functions for joining lists into natural language strings.
- Host: GitHub
- URL: https://github.com/oalders/go-joined
- Owner: oalders
- License: mit
- Created: 2021-08-10T22:01:34.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-12T02:22:25.000Z (over 4 years ago)
- Last Synced: 2025-02-16T01:42:44.466Z (about 1 year ago)
- Topics: golang, join, strings
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# joined
Provides functions for joining lists into natural language strings.
## Functions
### func [And](/joined.go#L8)
`func And(list []string) string`
And joins the last 2 elements of a list with " and ", while joining
preceding elements with a comma.
```golang
list := []string{"one", "two"}
fmt.Println(And(list)) // "one and two"
list = []string{"one", "two", "three"}
fmt.Println(And(list)) // "one, two and three"
```
### func [Arbitrary](/joined.go#L22)
`func Arbitrary(wordSeparator string, conjunction string, list []string) string`
Arbitrary joins the last 2 elements of a list with the supplied conjunction,
while joining preceding elements with the supplied word separator. Note
that you'll need to provide your own padding for both the word separator and
the conjunction.
```golang
list := []string{"eins", "zwei", "drei"}
fmt.Println(Arbitrary(", ", " und ", list)) // "eins, zwei und drei"
```
### func [Or](/joined.go#L14)
`func Or(list []string) string`
Or joins the last 2 elements of a list with " or ", while joining
preceding elements with a comma.
```golang
list := []string{"one", "two"}
fmt.Println(Or(list)) // "one or two"
list = []string{"one", "two", "three"}
fmt.Println(Or(list)) // "one, two or three"
```
---
Readme created from Go doc with [goreadme](https://github.com/posener/goreadme)