https://github.com/willf/pad
Left and Right padding of strings for Go
https://github.com/willf/pad
Last synced: about 1 year ago
JSON representation
Left and Right padding of strings for Go
- Host: GitHub
- URL: https://github.com/willf/pad
- Owner: willf
- License: bsd-2-clause
- Created: 2016-03-30T13:48:03.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-03-13T20:24:18.000Z (over 6 years ago)
- Last Synced: 2025-04-10T20:13:02.144Z (about 1 year ago)
- Language: Go
- Size: 5.86 KB
- Stars: 34
- Watchers: 2
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
pad
-------------
[](https://gitter.im/willf/pad?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://travis-ci.org/willf/pad)
A golang implementation of the [left-pad javascript library](https://www.npmjs.com/package/left-pad)
I was inspired by [Stew](https://twitter.com/StewOConnor)'s [`left-cats`](https://github.com/stew/left-cats), who was inspired by [this article](http://arstechnica.com/information-technology/2016/03/rage-quit-coder-unpublished-17-lines-of-javascript-and-broke-the-internet/), to port this to Go.
This implementation will let you pad byte-strings and UTF-8 encoded strings
example usage:
```go
package main
import (
"fmt"
"github.com/willf/pad"
padUtf8 "github.com/willf/pad/utf8"
)
func main() {
fmt.Println(pad.Right("Hello", 20, "!"))
fmt.Println(padUtf8.Left("Exit now", 20, "→"))
}
```
```bash
> go run example.go
Hello!!!!!!!!!!!!!!!
→→→→→→→→→→→→Exit now
```