Skip to content

Commit

Permalink
feat(clean): Add clear letter in the beginning of the word
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rianb committed Nov 18, 2020
1 parent 4e2cf46 commit af5d8f4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var LeoProfanity = {

return str;
},

/**
* Return current profanity words
*
Expand Down Expand Up @@ -131,9 +131,10 @@ var LeoProfanity = {
* @param {string} [replaceKey=*] one character only
* @returns {string}
*/
proceed: function(str, replaceKey) {
proceed: function(str, replaceKey, nbLetters) {
if (!str) return '';
if (typeof replaceKey === 'undefined') replaceKey = '*';
if (typeof nbLetters === 'undefined') nbLetters = 0;

var self = this;
var originalString = str;
Expand All @@ -150,7 +151,7 @@ var LeoProfanity = {
var badWords = [];
sanitizedArr.forEach(function(item, index) {
if (words.includes(item)) {
var replacementWord = self.getReplacementWord(replaceKey, item.length);
var replacementWord = item.slice(0, nbLetters) + self.getReplacementWord(replaceKey, item.length - nbLetters);
badWords.push(resultArr[index]);
resultArr[index] = replacementWord;
}
Expand All @@ -169,16 +170,17 @@ var LeoProfanity = {
* @param {string} [replaceKey=*] one character only
* @returns {string}
*/
clean: function(str, replaceKey) {
clean: function(str, replaceKey, nbLetters) {
if (!str) return '';
if (typeof replaceKey === 'undefined') replaceKey = '*';
return this.proceed(str, replaceKey)[0];
if (typeof nbLetters === 'undefined') nbLetters = 0;
return this.proceed(str, replaceKey, nbLetters)[0];
},

/**
* Get list of used bad/profanity words
*
* @param {string} str
* @param {string} str
* @returns {Array.string}
*/
badWordsUsed: function(str) {
Expand Down Expand Up @@ -241,7 +243,7 @@ var LeoProfanity = {

return this;
},

/**
* Return word list from dictionary
*
Expand Down

0 comments on commit af5d8f4

Please sign in to comment.