You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

good-censor

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

good-censor

A simple text censoring module.

1.1.1
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Good-Censor

A simple censoring module for all your needs.

Contents

  • Good-Censor

Installation

npm i --save good-censor

Usage

const GoodCensor = require('good-censor');

const badwords = [
    'duck',
    'ship',
    'sax',
    'nagger',
    'corn',
    'sick',
    'batch',
    'clip',
    'milk',
]

const myCensor = new GoodCensor(badwords)

const censored = myCensor.censor('duck you, you little batch');

console.log(censored) // "**** you, you little *****"

Options

// the following are the default values
const options = {
    censorText: '*',
    censorLoop: true,
    censorLongest: true,
    censorSlice: true,
    censorStart: 0,
    censorEnd: 0,
    ignore: /(?!)/
}
myCensor.censor('someString',options);
Note: examples below are pseudocode

options.censorText

options = {
    censorText: '#',
}
// result: #### you, you little #####

options = {
    censorText: '~BEEP~',
    censorSlice: false,
    censorLoop: false,
}
// result: ~BEEP~ you, you little ~BEEP~

options.censorLoop

options = {
    censorText: '#',
    censorLoop: false,
}
// result: # you, you little #

options = {
    censorText: 'NO',
    censorLoop: true,
    censorSlice: false,
}
// result: NONO you, you little NONONO

options.censorLongest

badwords = ['duck','ducking']
text = 'ducking'
options = {
    censorLongest: true,
}
// result: *******

badwords = ['duck','ducking']
text = 'ducking'
options = {
    censorLongest: false,
}
// result: ****ing

options.censorSlice

options = {
    censorText: 'AAAAAAAAAA',
    censorSlice: true,
}
// result: AAAA you, you little AAAAA

options = {
    censorText: 'AAAAAAAAAA',
    censorSlice: false,
}
// result: AAAAAAAAAA you, you little AAAAAAAAAA

options.censorStart

options = {
    censorStart: 1,
}
// result: d*** you, you little b****

options = {
    censorStart: 2,
}
// result: du** you, you little ba***

NOTE: if you put a number which is too big (especially in combination with options.censorEnd), the full word may get not censored.

options.censorEnd

options = {
    censorEnd: 1,
}
// result: ***k you, you little ****h

options = {
    censorEnd: 2,
}
// result: **ck you, you little ***ch

NOTE: if you put a number which is too big (especially in combination with options.censorStart), the full word may get not censored.

options.ignore

options = {
    ignore: /ck|ch/
}
// result: duck you, you little batch

NOTE: this is really useful in cases where you don't want to censure URLs or other specific strings. The flags will be forced to be iy

Keywords

good

FAQs

Package last updated on 03 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.