+0
日增长
+0
周增长
299
stars
58
forks
2
watchers
132
prs
29
issues
38
releases
README
!go-away
go-away
!test
go-away is a stand-alone, lightweight library for detecting and censoring profanities in Go.
This library must remain extremely easy to use. Its original intent of not adding overhead will always remain.
Installation
console
go get -u github.com/TwiN/go-away
Usage
go
package main
import (
"github.com/TwiN/go-away"
)
func main() {
goaway.IsProfane("fuck this shit") // returns true
goaway.ExtractProfanity("fuck this shit") // returns "fuck"
goaway.Censor("fuck this shit") // returns " this "
goaway.IsProfane("F u C k th1$ $h!t") // returns true
goaway.ExtractProfanity("F u C k th1$ $h!t") // returns "fuck"
goaway.Censor("F u C k th1$ $h!t") // returns " th1$ "
goaway.IsProfane("@$$h073") // returns true
goaway.ExtractProfanity("@$$h073") // returns "asshole"
goaway.Censor("@$$h073") // returns ""
goaway.IsProfane("hello, world!") // returns false
goaway.ExtractProfanity("hello, world!") // returns ""
goaway.Censor("hello, world!") // returns "hello, world!"
buf := &bytes.Buffer{}
detector := goaway.NewProfanityDetector()
writer := goaway.NewWriter(buf, detector)
writer.Write([]byte("fuck this shit"))
writer.Flush()
print(buf.String()) // returns " this "
}
Calling goaway.IsProfane(s), goaway.ExtractProfanity(s) or goaway.Censor(s) will use the default profanity detector,
but if you'd like to disable leet speak, numerical character or special character sanitization, you have to create a
ProfanityDetector instead:
go
profanityDetector := goaway.NewProfanityDetector().WithSanitizeLeetSpeak(false).WithSanitizeSpecialCharacters(false).WithSanitizeAccents(false)
profanityDetector.IsProfane("b!tch") // returns false because we're not sanitizing special characters
You can also disable the default behavior of white space sanitization like so:
go
profanityDetector := goaway.NewProfanityDetector().WithSanitizeSpaces(false)
profanityDetector.IsProfane("sh it") // returns false because we're not sanitizing white spaces
You can also require stricter matching by enabling WithExactWord:
go
profanityDetector := NewProfanityDetector().WithExactWord(true).WithSanitizeSpecialCharacters(true)
profanityDetector.IsProfane("analyst") // returns false because we match the exact word
profanityDetector.IsProfane("anal") // returns true
By default, the NewProfanityDetector constructor uses the default dictionaries for profanities, false positives and false negatives.
These dictionaries are exposed as goaway.DefaultProfanities, goaway.DefaultFalsePositives and goaway.DefaultFalseNegatives respectively.
If you need to load a different dictionary, you could create a new instance of ProfanityDetector on this way:
go
profanities Top issues
#28False positives: "can use", "via ssh"7 comments · 2022-04-17#38Filter only the exact words4 comments · 2022-08-24#8Collapse repeated characters (possibly using regex)1 comments · 2020-10-09#1Support profanity levels1 comments · 2018-11-11#142fix: False Positive (assault)0 comments · 2026-03-19#92Extract a list of bad words not just the first one 0 comments · 2024-06-27#70Fix (False Positive): Tassilo0 comments · 2023-11-28#46bug: incorrect position replaced0 comments · 2023-01-16
Latest release
v1.8.1 v1.8.1 2025-10-25What's Changed fix(ci): Bump Go to 1.24.4 by @TwiN chore(deps): bump golang.org/x/text from 0.29.0 to 0.30.0 by @dependabot[bot] in https://github.com/TwiN/go-away/pull/131 chore(deps): bump codecov/codecov-action from 5.4.3 to 5.5.1 by @dependabot[bot] in https://github.com/TwiN/go-away/pull/128 chore(deps): bump actions/setup-go from 5 to 6 by @dependabot[bot] in https://github.com/TwiN/go-away/pull/129 Full Changelog: https://github.com/TwiN/go-away/compare/v1.8.0...v1.8.1