good-censor
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Good-Censor

A simple censoring module for all your needs.

Contents

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

Package Sidebar

Install

npm i good-censor

Weekly Downloads

5

Version

1.1.1

License

MIT

Unpacked Size

12.5 kB

Total Files

7

Last publish

Collaborators

  • specky