2Toad / Profanity

A multi-language profanity filter with full TypeScript support
MIT License
80 stars 10 forks source link

Add partial grawlix option #16

Closed JasonPierce closed 2 years ago

JasonPierce commented 3 years ago

Presently, the censor method replaces the entire profane word with a grawlix. Thought it might be cool to add an option that only replaces the vowels in a profane word.

Acceptance Criteria

  1. Add optional usePartialGrawlix param to the censor method. Default to false.
  2. Add partialGrawlix option to ProfanityOptions. Defaults to '*'.
  3. When usePartialGrawlix is true, instead of the entire profane word being replaced with the grawlix, only the vowels are replaced within the profane word. Each vowel is replaced with the partialGrawlix value.
  4. Update readme Options section.

Example

Configure

import { Profanity, ProfanityOptions } from '@2toad/profanity';

const options = new ProfanityOptions();
options.partialGrawlix = '*';

const profanity = new Profanity(options);

Usage

profanity.censor('I like big butts (aka arses) and I cannot lie', true);
// I like big b*tts (aka *rs*s) and I cannot lie
JasonPierce commented 3 years ago

A better solution might be to replace the userPartialGrawlix param with grawlixReplacementType, which supports the following values

The grawlixChar option would replace the partialGrawlix option, in this design. 🤔

JasonPierce commented 2 years ago

I went with slightly different implementation than the original vision I had for this new feature:

A new, optional, CensorType param has been added to the censor function:

A new ProfanityOptions.grawlixChar option has been added, which defaults to *