{"id":16513912,"url":"https://github.com/twin/go-away","last_synced_at":"2025-05-16T07:03:22.673Z","repository":{"id":38994353,"uuid":"157039308","full_name":"TwiN/go-away","owner":"TwiN","description":"Library for detecting profanities in Go","archived":false,"fork":false,"pushed_at":"2025-05-05T23:53:31.000Z","size":600,"stargazers_count":215,"open_issues_count":10,"forks_count":48,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T00:36:23.113Z","etag":null,"topics":["bad-word-filter","bad-words","detecting-profanities","go","golang","golang-library","hacktoberfest","profanities","profanity","profanity-filter","swear","swear-filter","swearing","swearing-detector"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TwiN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["TwiN"]}},"created_at":"2018-11-11T02:07:22.000Z","updated_at":"2025-05-05T23:53:28.000Z","dependencies_parsed_at":"2024-05-01T22:57:15.146Z","dependency_job_id":"851c7960-42b5-47b5-9111-6dbcd7c208b9","html_url":"https://github.com/TwiN/go-away","commit_stats":null,"previous_names":["twinproduction/go-away"],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwiN%2Fgo-away","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwiN%2Fgo-away/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwiN%2Fgo-away/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwiN%2Fgo-away/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TwiN","download_url":"https://codeload.github.com/TwiN/go-away/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485052,"owners_count":22078767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bad-word-filter","bad-words","detecting-profanities","go","golang","golang-library","hacktoberfest","profanities","profanity","profanity-filter","swear","swear-filter","swearing","swearing-detector"],"created_at":"2024-10-11T16:10:50.044Z","updated_at":"2025-05-16T07:03:22.621Z","avatar_url":"https://github.com/TwiN.png","language":"Go","funding_links":["https://github.com/sponsors/TwiN"],"categories":[],"sub_categories":[],"readme":"![go-away](/.github/assets/go-away.png)\n\n# go-away\n![test](https://github.com/TwiN/go-away/workflows/test/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/TwiN/go-away)](https://goreportcard.com/report/github.com/TwiN/go-away)\n[![codecov](https://codecov.io/gh/TwiN/go-away/branch/master/graph/badge.svg)](https://codecov.io/gh/TwiN/go-away)\n[![Go Reference](https://pkg.go.dev/badge/github.com/TwiN/go-away.svg)](https://pkg.go.dev/github.com/TwiN/go-away)\n[![Follow TwiN](https://img.shields.io/github/followers/TwiN?label=Follow\u0026style=social)](https://github.com/TwiN)\n\ngo-away is a stand-alone, lightweight library for detecting and censoring profanities in Go.\n\nThis library must remain **extremely** easy to use. Its original intent of not adding overhead will always remain.\n\n\n## Installation\n```console\ngo get -u github.com/TwiN/go-away\n```\n\n\n## Usage\n```go\npackage main\n\nimport (\n    \"github.com/TwiN/go-away\"\n)\n\nfunc main() {\n    goaway.IsProfane(\"fuck this shit\")                // returns true\n    goaway.ExtractProfanity(\"fuck this shit\")         // returns \"fuck\"\n    goaway.Censor(\"fuck this shit\")                   // returns \"**** this ****\"\n    \n    goaway.IsProfane(\"F   u   C  k th1$ $h!t\")        // returns true\n    goaway.ExtractProfanity(\"F   u   C  k th1$ $h!t\") // returns \"fuck\"\n    goaway.Censor(\"F   u   C  k th1$ $h!t\")           // returns \"*   *   *  * th1$ ****\"\n    \n    goaway.IsProfane(\"@$$h073\")                       // returns true\n    goaway.ExtractProfanity(\"@$$h073\")                // returns \"asshole\"\n    goaway.Censor(\"@$$h073\")                          // returns \"*******\"\n    \n    goaway.IsProfane(\"hello, world!\")                 // returns false\n    goaway.ExtractProfanity(\"hello, world!\")          // returns \"\"\n    goaway.Censor(\"hello, world!\")                    // returns \"hello, world!\"\n}\n```\n\nCalling `goaway.IsProfane(s)`, `goaway.ExtractProfanity(s)` or `goaway.Censor(s)` will use the default profanity detector,\nbut if you'd like to disable leet speak, numerical character or special character sanitization, you have to create a\nProfanityDetector instead:\n```go\nprofanityDetector := goaway.NewProfanityDetector().WithSanitizeLeetSpeak(false).WithSanitizeSpecialCharacters(false).WithSanitizeAccents(false)\nprofanityDetector.IsProfane(\"b!tch\") // returns false because we're not sanitizing special characters\n```\n\nBy default, the `NewProfanityDetector` constructor uses the default dictionaries for profanities, false positives and false negatives.\nThese dictionaries are exposed as `goaway.DefaultProfanities`, `goaway.DefaultFalsePositives` and `goaway.DefaultFalseNegatives` respectively.\n\nIf you need to load a different dictionary, you could create a new instance of `ProfanityDetector` on this way:\n```go\nprofanities    := []string{\"ass\"}\nfalsePositives := []string{\"bass\"}\nfalseNegatives := []string{\"dumbass\"}\n\nprofanityDetector := goaway.NewProfanityDetector().WithCustomDictionary(profanities, falsePositives, falseNegatives)\n```\n\nYou may also specify custom character replacements using `WithCustomCharacterReplacements` on a `ProfanityDetector`.\nBy default, this is set to `goaway.DefaultCharacterReplacements`.\n\nNote that all character replacements with a value of `' '` are considered as special characters while all characters\nwith a value that is not `' '` are considered to be leetspeak characters. This means that using \n`profanityDetector.WithSanitizeSpecialCharacters(bool)` and `profanityDetector.WithSanitizeLeetSpeak(bool)` will let you\ntoggle which character replacements are executed during the sanitization process.\n\n## Limitations\nCurrently, go-away does not support UTF-8. As such, if the strings you are feeding to this library come from unsanitized user input, you\nare advised to filter out all non-ASCII characters.\n\nIf you'd like to add support for UTF-8, see [#43](https://github.com/TwiN/go-away/issues/43) and [#47](https://github.com/TwiN/go-away/issues/47).\n\n\n## In the background\nWhile using a giant regex query to handle everything would be a way of doing it, as more words \nare added to the list of profanities, that would slow down the filtering considerably.\n\nInstead, the following steps are taken before checking for profanities in a string:\n\n- Numbers are replaced to their letter counterparts (e.g. 1 -\u003e L, 4 -\u003e A, etc)\n- Special characters are replaced to their letter equivalent (e.g. @ -\u003e A, ! -\u003e i)\n- The resulting string has all of its spaces removed to prevent `w  ords  lik e   tha   t`\n- The resulting string has all of its characters converted to lowercase\n- The resulting string has all words deemed as false positives (e.g. `assassin`) removed\n\nIn the future, the following additional steps could also be considered:\n- All non-transformed special characters are removed to prevent `s~tring li~ke tha~~t`\n- All words that have the same character repeated more than twice in a row are removed (e.g. `poooop -\u003e poop`)\n  - NOTE: This is obviously not a perfect approach, as words like `fuuck` wouldn't be detected, but it's better than nothing.\n  - The upside of this method is that we only need to add base bad words, and not all tenses of said bad word. (e.g. the `fuck` entry would support `fucker`, `fucking`, etc.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwin%2Fgo-away","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwin%2Fgo-away","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwin%2Fgo-away/lists"}