1.0.0 • Published 4 years ago

@clickteam/censor-js v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

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

NameDescription
whitelistjs object with the structure above
fixedAllowedWordsfixed words that are part of the format, for example props name
fixedAllowedCharsfixed chars that are part of the format, for example '{', ',' etc..
prefixAllowedLettersCounthow match letters you allow to show start from the prefix, value=2 'hello' -> 'he***'
suffixAllowedLettersCounthow match letters you allow to show start from the suffix, value=2 'hello' -> '***lo'
mixSpaceBetweenPrefixAndSuffixhow match letters you allow to hide from prefix to suffix
replaceStringchar value to replace all other chars

License

ISC