https://github.com/jimschubert/stripansi
Strip ansi escape codes, ala chalk/strip-ansi
https://github.com/jimschubert/stripansi
go golang
Last synced: 20 days ago
JSON representation
Strip ansi escape codes, ala chalk/strip-ansi
- Host: GitHub
- URL: https://github.com/jimschubert/stripansi
- Owner: jimschubert
- License: mit
- Created: 2022-11-13T22:18:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-13T23:01:23.000Z (over 3 years ago)
- Last Synced: 2025-10-17T03:04:55.151Z (10 months ago)
- Topics: go, golang
- Language: Go
- Homepage: https://pkg.go.dev/github.com/jimschubert/stripansi
- Size: 2.93 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stripansi
[](https://godoc.org/github.com/jimschubert/stripansi)
This is a port of Sindre Sorhus's excellent [chalk/strip-ansi](https://github.com/chalk/strip-ansi) to Go.
It's useful for stripping ANSI escape codes from strings or byte slices, which is often necessary when processing CLI output for logs, tests, or other text-based tools.
## Install
```
$ go get -u github.com/jimschubert/stripansi
```
## Usage
### Strings
```go
package main
import (
"fmt"
"github.com/jimschubert/stripansi"
)
func main() {
result := stripansi.String("\x1b[30mfoo\x1b[0m \x1b[30mbar\x1b[0m \x1b[30mbaz\x1b[0m")
fmt.Println(result)
// Output: foo bar baz
}
```
### Bytes
```go
package main
import (
"fmt"
"github.com/jimschubert/stripansi"
)
func main() {
result := stripansi.Bytes([]byte("\x1b[30mfoo\x1b[0m"))
fmt.Printf("%s\n", result)
// Output: foo
}
```
## License
This is [licensed](./LICENSE) under MIT.