@clickteam/censor-js

censor words

Usage no npm install needed!

<script type="module">
  import clickteamCensorJs from 'https://cdn.skypack.dev/@clickteam/censor-js';
</script>

README

Censor-JS

censor-js is a javascript library for censor stringified json with a whitelist for nodejs.

Installation

Use the package manager npm to install censor-js.

npm install @clickteam/censor-js

Usage

const { Censor } = require('censor-js');

const text = `{
    "calender-name": "test",
    "calender": {
        "day-1" {
            "description": "testing the library",
            "content": "the library works awesome"
        }
    }
}`;

const censor = new Censor({
    whitelist: {
        "testing": true,
        "the": {
            "library": {
                "works": false,
                "is": {
                    "sucks": false
                }
            }
        },
    },
    fixedAllowedWords: {
        "calender-name": true,
        "calender": true,
        "day-1": true,
        "desctiption": true,
        "content": true
    },
    fixedAllowedChars: [
        "{",
        "}",
        ":",
        ",",
        "."
    ],
    prefixAllowedLettersCount: 1,
    suffixAllowedLettersCount: 0,
    mixSpaceBetweenPrefixAndSuffix: 1,
    replaceString: '*'
});

const censorText = censor.replaceFromJson(text);

Props

Name Description
whitelist js object with the structure above
fixedAllowedWords fixed words that are part of the format, for example props name
fixedAllowedChars fixed chars that are part of the format, for example '{', ',' etc..
prefixAllowedLettersCount how match letters you allow to show start from the prefix, value=2 'hello' -> 'he***'
suffixAllowedLettersCount how match letters you allow to show start from the suffix, value=2 'hello' -> '***lo'
mixSpaceBetweenPrefixAndSuffix how match letters you allow to hide from prefix to suffix
replaceString char value to replace all other chars

License

ISC