Giter Site home page Giter Site logo

pcpratheesh / go-censorword Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 4.0 21 KB

A lightweight and easy-to-use tool that allows you to detect and filter out profanity words from your text-based content. Whether you're building a social media platform, a chat app, or just want to keep your comments section clean, this package can help.

Home Page: https://pkg.go.dev/github.com/pcpratheesh/go-censorword

License: MIT License

Go 100.00%
golang go profanities censored-words censor censoring bad-word-filter profanity-filter profanityfilter badwords

go-censorword's Introduction

Create Release

go-censorword

go-censorword is a lightweight and easy-to-use tool that allows you to detect and filter out profanity words from your text-based content. Whether you're building a social media platform, a chat app, or just want to keep your comments section clean, this package can help.

Installation

    go get -u github.com/pcpratheesh/go-censorword

for previous version

    go get -u github.com/pcpratheesh/[email protected]

Usage

import (
	"github.com/pcpratheesh/go-censorword"
)

In working

The go-censorword package uses a censorWord here list to check profanities, but also provides an option for you to override this list with your own contents. You can create a list of bad words that are not included in the original blacklist by using the customCensorList method.

CustomCensorList([]string{}) 

How to use

// this would initialize the detector object.
var detector = gocensorword.NewDetector(
	gocensorword.WithCensorReplaceChar("*"),
    
    // override the existing list of bad words with your own
    gocensorword.WithCustomCensorList([]string{
        "bad", "word","one",
    }),
)

// censor the word
actualString := "with having some bad words"
filterString, err := detector.CensorWord(actualString)
if err != nil {
    panic(err)
}

Option Methods

  • WithCensorReplaceChar(string) : This method can be used to replace the filtered word characters with asterisks (*), dashes (-) or custom characters, like the pound sign (#) or at sign (@).
  • WithCustomCensorList([]string) : The list of your own profanity words
  • WithSanitizeSpecialCharacters(bool): To sanitize the special characters in the word
  • WithKeepPrefixChar(bool): If you want to Kept the prefix Character (eg : F****)
  • WithKeepSuffixChar(bool): If you want to Kept the suffix Character (eg : ****K)

Example

detector := NewDetector(
    gocensorword.WithCensorReplaceChar("*"),
)

resultString, err := detector.CensorWord(inputString)

if err != nil {
    panic(err)
}

In the future, we should implement the following points

  • Support for other language profanities
  • All words having repeated characters more than twice

Contributing

Contributions to the Profanity Filter package are welcome and encouraged! If you find a bug or have a feature request, please open an issue on GitHub. If you'd like to contribute code, please fork the repository, make your changes, and submit a pull request.

License

The Profanity Filter package is licensed under the MIT License. See the LICENSE file for more information.

go-censorword's People

Contributors

pcpratheesh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.