1.3.2 • Published 2 years ago

nepali-profanity-detector v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

nepali-profanity-detector

Detect Nepali profane words with configurable options.

Install

npm i nepali-profanity-detector

Usage

import { hasProfane } from "nepali-profanity-detector";

console.log(hasProfane("Oi muji")); // true
console.log(hasProfane("Oi mUjI")); // true
console.log(hasProfane("Oi yaar")); // false

// detects accent by default
console.log(hasProfane("Oi ḿüjį")); // true

// change behavior to throw error
hasProfane("Oi muji", { behavior: "THROW_ERR" }); // throws new Error("Nepali profanity detected")

// change behavior to throw custom error
hasProfane("Oi muji", {
  behavior: "THROW_ERR",
  error: new AppError("My Custom Error", 400),
}); // throws new new AppError("My Custom Error", 400)

// add your custom profane by blacklisting them
console.log(hasProfane("test", { blacklist: ["test"] })); // true

// whitelist your custom words
console.log(hasProfane("muji", { whitelist: ["muji"] })); // false

You also have the option to import Behavior as follows:

import { hasProfane, Behavior } from "nepali-profanity-detector";

// throws error
hasProfane("muji", { behavior: Behavior.THROW_ERR });

// returns boolean, also default behavior so you can omit behavior option
hasProfane("muji", { behavior: Behavior.RETURN_BOOLEAN });

options

KeyDescriptionDefault
includeAccentsAllows accents like ä to be interpreted as a.true
trimSymbolsRemoves any non-alphanumeric characters. For eg. m.u.j.i will be interpreted as muji.true
behaviorChange whether the function should return boolean or throw error if profanity is detected.Behavior.RETURN_BOOLEAN
errorPass custom error to be thrown IF behavior is set to "THROW_ERR" or Behavior.THROW_ERRnew Error("Nepali profanity detected")
blacklistPass your custom profane words in an array of strings.[]
whitelistPass your custom words to be ignored when detecting profane.[]

Precedence

Whitelisting words take precedence over blacklisting the same words.

Roadmap

  • Handle Accents
  • Throw Error Behaviour Option
  • Usage Documentation with examples
  • @use JSDoc
  • Whitelisting support
  • Further Blacklisting support
  • Automate Code Linting
  • Test Coverage
  • Handle Leetspeaks
1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago