bad-words-next
Advanced tools
Comparing version 1.5.3 to 1.6.0
@@ -171,7 +171,8 @@ /** | ||
* @param {string} | ||
* @param {(badword: string) => void} | ||
* @return {string} | ||
*/ | ||
filter(str: string): string; | ||
filter(str: string, onBadword?: (badword: string) => void): string; | ||
} | ||
export { Data, Lookalike, Options, BadWordsNext as default }; |
@@ -278,3 +278,3 @@ 'use strict'; | ||
key: "filter", | ||
value: function filter(str) { | ||
value: function filter(str, onBadword) { | ||
var _this2 = this; | ||
@@ -289,3 +289,9 @@ if (str === '' || this.check(str) === false) return str; | ||
return str.split(/[\b\s]/).map(function (p) { | ||
return _this2.check(p) === true ? _this2.opts.placeholder : p; | ||
if (_this2.check(p) === true) { | ||
if (onBadword !== undefined) { | ||
onBadword(p); | ||
} | ||
return _this2.opts.placeholder; | ||
} | ||
return p; | ||
}).reduce(function (a, s, i) { | ||
@@ -292,0 +298,0 @@ return a + (i > 0 ? delims[i - 1] === undefined ? ' ' : delims[i - 1] : '') + s; |
{ | ||
"name": "bad-words-next", | ||
"version": "1.5.3", | ||
"version": "1.6.0", | ||
"description": "JavaScript/TypeScript filter and checker for bad words aka profanity", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -41,2 +41,8 @@ # bad-words-next | ||
// will print `S0me *** is here` | ||
// Returns filtered string and catches bad words | ||
badwords.filter('S0me sh!tt is here', badword => { | ||
console.log(badword) | ||
}) | ||
// will print `sh!tt` | ||
``` | ||
@@ -43,0 +49,0 @@ |
@@ -53,2 +53,11 @@ import BadWordsNext from '../src' | ||
}) | ||
it('filters and reports back with callback function', () => { | ||
const badwords = new BadWordsNext({ data: en }) | ||
const detected: string[] = [] | ||
badwords.filter('hello sex sex3 b0000b test b00b anyfuckany pussy cat', (badword: string) => { | ||
detected.push(badword) | ||
}) | ||
expect(detected).toStrictEqual(['sex', 'sex3', 'b0000b', 'b00b', 'anyfuckany', 'pussy']) | ||
}) | ||
}) | ||
@@ -55,0 +64,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
53015
1909
116