Redact

Redact

  • Docs
  • Help
  • Blog

›Guides

Getting Started

  • Installing Redact
  • Updating Redact

Guides

  • Blacklist
  • Whitelist
  • Redact
  • Blacklist Check
  • Blacklist Count

Utils

  • Available lists

Filtering strings or sentences

This works by replacing blacklisted words with grawlix. A grawlix is string of typographical symbols used to replace/censor words.

Syntax

redact(string: string, blacklist: string[], options?: object): string

Parameters

string: string - Given string/sentence to be filtered.

blacklist: string[] - Blacklist

options - Additional options that may be passed.

Options

props default description
grawlix * Character used to replace the blacklisted word.
replaceByLength true Determines if the blacklisted word should be replaced by its word length or only once
caseSensitive false Determines if the check for a blacklisted word in a sentence is case sensitive

Returns

string - The resulting sentence/string that has its blacklisted words replaced by a grawlix.

Error

Throws an error if the required parameters are not given to the function.

Import

import { redact } from '@princedev/redact';

Examples

Basic Usage

Basic usage with default options.

const racialBlacklist = blacklist('nigga', 'eskimo');
const redactSentence = redact('Wassup my nigga', racialBlacklist)

redactSentence would be 'Wassup my *****'.

Grawlix Usage

Usage with changing the grawlix option.

const racialBlacklist = blacklist('nigga', 'eskimo');
const redactSentence = redact('Wassup my nigga', racialBlacklist, {
  grawlix: '$',
});

redactSentence would be 'Wassup my $$$$$'.

Replace by Length Usage

Usage with turning off replace by length

const racialBlacklist = blacklist('nigga', 'eskimo');
const redactSentence = redact('Wassup my nigga', racialBlacklist, {
  replaceByLength: false,
});

redactSentence would be 'Wassup my $'.

Case Sensitive Usage

Usage with turning off replace by length

const racialBlacklist = blacklist('nigga', 'eskimo');
const redactSentence = redact('Wassup my Nigga-nigga', racialBlacklist, {
  caseSensitive: true,
});

redactSentence would be 'Wassup my Nigga-*****'.

Multiple Option Usage

Usage with multiple options.

const racialBlacklist = blacklist('nigga', 'eskimo');
const redactSentence = redact('Wassup my nigga', racialBlacklist, {
  grawlix: 'censored',
  replaceByLength: false,
  caseSensitive: false,
});

redactSentence would be 'Wassup my censored'.

Last updated on 7/22/2020 by Prince Neil Cedrick Castro
← WhitelistBlacklist Check →
  • Syntax
    • Parameters
    • Returns
    • Error
  • Import
  • Examples
    • Basic Usage
    • Grawlix Usage
    • Replace by Length Usage
    • Case Sensitive Usage
    • Multiple Option Usage
Redact
Docs
Getting StartedGuides
Package
NPMGitHubStar
More
HelpBlog
aws.cedi@gmail.com
Copyright © 2020 Redact