bad-words-next
Advanced tools
Comparing version 1.0.5 to 1.0.6
/** | ||
* @license bad-words-next | ||
* Copyright (c) 2022, Alex Zelensky. (MIT License) | ||
* https://github.com/alexzel/bad-words-next | ||
* bad-words-next | ||
* | ||
* @author Alex Zelensky | ||
* @copyright Copyright (c) 2022, Alex Zelensky. (MIT License) | ||
* @license MIT | ||
*/ | ||
/** | ||
* Simple key-value object for homoglyphs conversion | ||
*/ | ||
interface Lookalike { | ||
[key: string | number]: string; | ||
} | ||
/** | ||
* Dictionary data format | ||
*/ | ||
interface Data { | ||
/** | ||
* Unique dictionary ID | ||
* @type {string} | ||
*/ | ||
id: string; | ||
/** | ||
* Words list | ||
* @type {string[]} | ||
*/ | ||
words: string[]; | ||
/** | ||
* Lookalike homoglyphs map | ||
* @type {Lookalike} | ||
*/ | ||
lookalike: Lookalike; | ||
} | ||
/** | ||
* Dictionaries data map | ||
*/ | ||
interface DataMap { | ||
[key: string]: Data; | ||
} | ||
/** | ||
* Constructor options | ||
*/ | ||
interface Options { | ||
/** | ||
* Dictionary data | ||
* @type {[type]} | ||
*/ | ||
data?: Data; | ||
/** | ||
* Filter placeholder | ||
* @defaultValue <code>'***'</code> | ||
* @type {[type]} | ||
*/ | ||
placeholder?: string; | ||
/** | ||
* Special chars to allow on start and end of a word | ||
* @defaultValue <code>/\d|[!@#$%^&*()[\\];:'",.?\\-_=+~`|]|a|(?:the)|(?:el)|(?:la)/</code> | ||
* @type {[type]} | ||
*/ | ||
specialChars?: RegExp; | ||
/** | ||
* Pseudo space chars, a list of values for `_` symbol replacement in a dictionary word string | ||
* @defaultValue <code>['', '.', '-', '_', ';', '|']</code> | ||
*/ | ||
spaceChars?: string[]; | ||
/** | ||
* List of dictionary ids to apply transformations from [confusables](https://github.com/gc/confusables) npm package | ||
* @defaultValue <code>['en', 'es', 'de']</code> | ||
*/ | ||
confusables?: string[]; | ||
} | ||
/** | ||
* Required constructor options for internal store | ||
*/ | ||
interface RequiredOptions { | ||
@@ -31,2 +82,5 @@ data: Data; | ||
} | ||
/** | ||
* Internal word representation | ||
*/ | ||
interface Word { | ||
@@ -36,15 +90,75 @@ id: string; | ||
} | ||
/** | ||
* Main library class implementing profanity filtering and detection | ||
*/ | ||
declare class BadWordsNext { | ||
/** | ||
* Options object built from options passed into constructor and default options object | ||
* @private | ||
* @type {RequiredOptions} | ||
*/ | ||
opts: RequiredOptions; | ||
/** | ||
* Special chars represented as string from specialChars regular expression | ||
* @private | ||
* @type {string} | ||
*/ | ||
specialChars: string; | ||
/** | ||
* Words list arrived from dictionaries data | ||
* @private | ||
* @type {Word[]} | ||
*/ | ||
words: Word[]; | ||
/** | ||
* Dictionaries data map with data ID as a key | ||
* @private | ||
* @type {DataMap} | ||
*/ | ||
data: DataMap; | ||
/** | ||
* Create an instance of BadWordsNext class | ||
* | ||
* @param {Options} | ||
*/ | ||
constructor(opts?: Options); | ||
/** | ||
* Add dictionary data for bad words filtering and detection | ||
* | ||
* @param {Data} data Dictionary data | ||
*/ | ||
add(data: Data): void; | ||
/** | ||
* Prepare a string by replacing dictionary lookalikes and homoglyphs | ||
* | ||
* @private | ||
* @param {string} str input string | ||
* @param {string} id dictionary ID | ||
* @return {string} | ||
*/ | ||
prepare(str: string, id: string): string; | ||
/** | ||
* Create regular expression by dictionary word expression string | ||
* | ||
* @private | ||
* @param {string} | ||
* @return {RegExp} | ||
*/ | ||
regexp(expr: string): RegExp; | ||
/** | ||
* Check whether the input string contains bad words or not | ||
* | ||
* @param {string} | ||
* @return {Boolean} | ||
*/ | ||
check(str: string): Boolean; | ||
/** | ||
* Filter bad words in the input string and replace them with a placeholder | ||
* | ||
* @param {string} | ||
* @return {string} | ||
*/ | ||
filter(str: string): string; | ||
} | ||
export { BadWordsNext as default }; | ||
export { Data, Lookalike, Options, BadWordsNext as default }; |
@@ -177,3 +177,10 @@ 'use strict'; | ||
// TODO: implement excludes? | ||
/** | ||
* Simple key-value object for homoglyphs conversion | ||
*/ | ||
/** | ||
* Default options object to use in BadWordsNext class contructor | ||
* @type {Object} | ||
*/ | ||
var DEFAULT_OPTIONS = { | ||
@@ -190,4 +197,36 @@ data: { | ||
}; | ||
/** | ||
* Main library class implementing profanity filtering and detection | ||
*/ | ||
var BadWordsNext = /*#__PURE__*/function () { | ||
/** | ||
* Options object built from options passed into constructor and default options object | ||
* @private | ||
* @type {RequiredOptions} | ||
*/ | ||
/** | ||
* Special chars represented as string from specialChars regular expression | ||
* @private | ||
* @type {string} | ||
*/ | ||
/** | ||
* Words list arrived from dictionaries data | ||
* @private | ||
* @type {Word[]} | ||
*/ | ||
/** | ||
* Dictionaries data map with data ID as a key | ||
* @private | ||
* @type {DataMap} | ||
*/ | ||
/** | ||
* Create an instance of BadWordsNext class | ||
* | ||
* @param {Options} | ||
*/ | ||
function BadWordsNext(opts) { | ||
@@ -202,3 +241,9 @@ _classCallCheck(this, BadWordsNext); | ||
} | ||
/** | ||
* Add dictionary data for bad words filtering and detection | ||
* | ||
* @param {Data} data Dictionary data | ||
*/ | ||
_createClass(BadWordsNext, [{ | ||
@@ -256,2 +301,11 @@ key: "add", | ||
} | ||
/** | ||
* Prepare a string by replacing dictionary lookalikes and homoglyphs | ||
* | ||
* @private | ||
* @param {string} str input string | ||
* @param {string} id dictionary ID | ||
* @return {string} | ||
*/ | ||
}, { | ||
@@ -267,2 +321,10 @@ key: "prepare", | ||
} | ||
/** | ||
* Create regular expression by dictionary word expression string | ||
* | ||
* @private | ||
* @param {string} | ||
* @return {RegExp} | ||
*/ | ||
}, { | ||
@@ -273,2 +335,9 @@ key: "regexp", | ||
} | ||
/** | ||
* Check whether the input string contains bad words or not | ||
* | ||
* @param {string} | ||
* @return {Boolean} | ||
*/ | ||
}, { | ||
@@ -296,2 +365,9 @@ key: "check", | ||
} | ||
/** | ||
* Filter bad words in the input string and replace them with a placeholder | ||
* | ||
* @param {string} | ||
* @return {string} | ||
*/ | ||
}, { | ||
@@ -298,0 +374,0 @@ key: "filter", |
{ | ||
"name": "bad-words-next", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Profanity filtering and detection", | ||
@@ -29,4 +29,5 @@ "keywords": [ | ||
"lint": "eslint ./src", | ||
"doc": "typedoc --options typedoc.json", | ||
"release": "yarn version", | ||
"preversion": "yarn install && yarn build && yarn test", | ||
"preversion": "yarn install && yarn build && yarn test && yarn doc", | ||
"postversion": "git push --tags && yarn publish . --new-version $npm_package_version && git push && echo Successfully released version $npm_package_version!", | ||
@@ -40,3 +41,4 @@ "cleanup": "git tag -d $(git tag) && git fetch --all --tags && git clean --force -d -x && git reset --hard origin/main && git checkout main" | ||
"lib", | ||
"data" | ||
"data", | ||
"doc" | ||
], | ||
@@ -62,2 +64,6 @@ "devDependencies": { | ||
"rollup-plugin-dts": "^4.2.2", | ||
"typedoc": "^0.23.15", | ||
"typedoc-github-wiki-theme": "^1.0.1", | ||
"typedoc-plugin-markdown": "^3.13.6", | ||
"typedoc-plugin-rename-defaults": "^0.6.4", | ||
"typescript": "^4.8.3" | ||
@@ -64,0 +70,0 @@ }, |
@@ -7,2 +7,4 @@ # bad-words-next | ||
API documentation in [GitHub Wiki](https://github.com/alexzel/bad-words-next/wiki/BadWordsNext). | ||
## Install | ||
@@ -9,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71198
21
1697
98
23