From 32469f9d00b969d069710e458fecbee704b8e09e Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:31:15 +0700 Subject: [PATCH 01/44] badword.js --- badword.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/badword.js b/badword.js index deb1d89..0675162 100644 --- a/badword.js +++ b/badword.js @@ -4,7 +4,7 @@ class FilterBadWord{ this.word = word; - this.filt = /bashfull*|kill*|fuck*|drug*|dick*|fk/gi; + this.filt = /b[[a4][s5]hfu[l1][l1]*|k[i1][l1][l1]*|fuck*|dr[uo]g*|d[i1]ck*|fk/gi; this.subfilter = /ass|lip|pussy*|suck*|mother*|mom*|dog*|low*|sex*/gi; From 2b8f29daaf8b8cf7b0fbd3a9a84fad6d56d859e1 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Thu, 10 Oct 2024 06:09:38 +0700 Subject: [PATCH 02/44] badword.js --- badword.js | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/badword.js b/badword.js index 0675162..f540331 100644 --- a/badword.js +++ b/badword.js @@ -1,16 +1,37 @@ +function escapeRegExp(strings){ + let data = strings.trim().toLowerCase().split("|").filter(Boolean); + for (let index = 0; index < data.length; index++) { + const element = data[index]; + if (!((element.includes("(") && element.includes(")")) || + (element.includes("[") && element.includes("]")) ) ){ + data[index] = data[index].replace(/[.*+?^${}()|[\]\\]/g, '\\$&'). + replace(/[a4]/g, "[a4]").replace(/[s5]/g, "[s5]").replace("i", "[i1]"). + replace("[l1]", "l").replace(/[o0]/g, "[o0]").replace(/[e3]/g, "[e3]"); + }; + } + data = new RegExp(data.join("|")); + return data.source; +}; + class FilterBadWord{ - constructor(word = ""){ - + constructor(word = "", customFilter="", customSubFilter=""){ + this.word = word; - this.filt = /b[[a4][s5]hfu[l1][l1]*|k[i1][l1][l1]*|fuck*|dr[uo]g*|d[i1]ck*|fk/gi; + this.filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|fk/gi; - this.subfilter = /ass|lip|pussy*|suck*|mother*|mom*|dog*|low*|sex*/gi; - + this.subfilter = /[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|[s5]uck[*]?|m[o0]th[e3]r[*]?|m[o0]m[*]?|d[o0]g[*]?|l[o0]w[*]?|s[e3]x[*]?/gi; + if (customFilter){ + this.filt = new RegExp(this.filt.source+"|"+escapeRegExp(customFilter), "gi"); + }; + if (customSubFilter){ + this.subfilter = new RegExp(this.subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); + }; } + static getboundPosition(word, _position){ var paragap, end; @@ -312,11 +333,15 @@ class filters_badword extends FilterBadWord{ } - ['config'](cl=true, smart=true, er=false){ - + ['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ this.cl = cl; this.st = smart; - this.er = er; + if (customFilter){ + this.filt = new RegExp(this.filt.source+"|"+escapeRegExp(customFilter), "gi"); + }; + if (customSubFilter){ + this.subfilter = new RegExp(this.subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); + }; } get ['cleans'](){ From 58f6d72a28159d0f01ba3e854e8bbce528f7af56 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:03:20 +0700 Subject: [PATCH 03/44] badword.js --- badword.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/badword.js b/badword.js index f540331..5b5669b 100644 --- a/badword.js +++ b/badword.js @@ -103,13 +103,7 @@ class FilterBadWord{ var check = this.position(); - var after = ""; - - var before = ""; - - var arry = []; - - var check_repr = ""; + var after ="", before ="", check_repr =""; if (check != null || check != 0) { From 7f02a172b41531a0d57020511b3aaec481ccf7fb Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:08:24 +0700 Subject: [PATCH 04/44] badword.js --- badword.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/badword.js b/badword.js index 5b5669b..e9b2b46 100644 --- a/badword.js +++ b/badword.js @@ -6,13 +6,15 @@ function escapeRegExp(strings){ (element.includes("[") && element.includes("]")) ) ){ data[index] = data[index].replace(/[.*+?^${}()|[\]\\]/g, '\\$&'). replace(/[a4]/g, "[a4]").replace(/[s5]/g, "[s5]").replace("i", "[i1]"). - replace("[l1]", "l").replace(/[o0]/g, "[o0]").replace(/[e3]/g, "[e3]"); + replace("l", "[l1]").replace(/[o0]/g, "[o0]").replace(/[e3]/g, "[e3]"). + replace(/[b8]/g, "[b8]"); }; } data = new RegExp(data.join("|")); return data.source; }; + class FilterBadWord{ constructor(word = "", customFilter="", customSubFilter=""){ From 39785c2cafbc5f6f7c51b35e4632cc7c814e52e9 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:30:29 +0700 Subject: [PATCH 05/44] badword.js --- badword.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/badword.js b/badword.js index e9b2b46..bcfdfa9 100644 --- a/badword.js +++ b/badword.js @@ -378,4 +378,19 @@ class filters_badword extends FilterBadWord{ } -} +}; + +// Definisikan objek ekspor +const exportsObject = { + FilterBadWord, + filters_badword +}; + +// Periksa lingkungan eksekusi +if (typeof exports === 'object' && typeof module !== 'undefined') { + // Ekspor ke Node.js + module.exports = exportsObject; +}else { + // Ekspor ke browser + Object.assign(window, exportsObject); +}; From 7e3f07b1ed79034336473b79faa5b2dd39bf623e Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:53:54 +0700 Subject: [PATCH 06/44] badword.js --- badword.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/badword.js b/badword.js index bcfdfa9..e309ed4 100644 --- a/badword.js +++ b/badword.js @@ -382,7 +382,17 @@ class filters_badword extends FilterBadWord{ // Definisikan objek ekspor const exportsObject = { + /** + * FilterBadWord class: class for filtering bad words + *@param {string} text - The text to filter + *@param {string} customFilter - List of bad words + *@param {string} customSubFilter - List of bad sub words + */ FilterBadWord, + /** + * filters_badword class: a simpler class to filter bad words + * which uses the FilterBadWord class. To use it you have to call the config function + */ filters_badword }; From 82175868396e814724532869570e8cb5bdb920dd Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 11:11:37 +0700 Subject: [PATCH 07/44] badword.js --- badword.js | 64 +++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/badword.js b/badword.js index e309ed4..4f774d7 100644 --- a/badword.js +++ b/badword.js @@ -17,18 +17,18 @@ function escapeRegExp(strings){ class FilterBadWord{ - constructor(word = "", customFilter="", customSubFilter=""){ + constructor(text = "", customFilter="", customSubFilter=""){ - this.word = word; + this._text = text; - this.filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|fk/gi; + this._filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|fk/gi; - this.subfilter = /[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|[s5]uck[*]?|m[o0]th[e3]r[*]?|m[o0]m[*]?|d[o0]g[*]?|l[o0]w[*]?|s[e3]x[*]?/gi; + this._subfilter = /[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|[s5]uck[*]?|m[o0]th[e3]r[*]?|m[o0]m[*]?|d[o0]g[*]?|l[o0]w[*]?|s[e3]x[*]?/gi; if (customFilter){ - this.filt = new RegExp(this.filt.source+"|"+escapeRegExp(customFilter), "gi"); + this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); }; if (customSubFilter){ - this.subfilter = new RegExp(this.subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); + this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; } @@ -95,7 +95,7 @@ class FilterBadWord{ //if ( typeof position != "number" ) { //position = parseInt(position); //} - this.positionList = this.constructor.position_static(this.word.toString(), this.filt); + this.positionList = this.constructor.position_static(this._text.toString(), this._filt); return this.positionList; @@ -109,7 +109,7 @@ class FilterBadWord{ if (check != null || check != 0) { - var word = this.word.toLowerCase(); + var word = this._text.toLowerCase(); function before_str(number , key){ @@ -124,11 +124,11 @@ class FilterBadWord{ for (var i = 0; i < check.length; i++) { - const word_s = this.constructor.getboundPosition(this.word.toLowerCase().toString() , check[i]); + const word_s = this.constructor.getboundPosition(this._text.toLowerCase().toString() , check[i]); before = before_str(0 , word_s).toString().split(" "); - after = after_Str(word_s, this.word).toString().split(" "); + after = after_Str(word_s, this._text).toString().split(" "); //console.log(word.indexOf(word_s)); if (after.length >= 1 ){ @@ -158,9 +158,9 @@ class FilterBadWord{ try{ - if (before[before.length-1].match(this.subfilter) != null) { + if (before[before.length-1].match(this._subfilter) != null) { - check_repr = before[before.length-1].match(this.subfilter); + check_repr = before[before.length-1].match(this._subfilter); if (check_repr != before[before.length-1]) { //check ulang jika sensore tidak memenuhi persyaratan @@ -181,9 +181,9 @@ class FilterBadWord{ } - else if (after[0].match(this.subfilter) != null){ + else if (after[0].match(this._subfilter) != null){ - check_repr = after[0].match(this.subfilter); + check_repr = after[0].match(this._subfilter); if (check_repr != after[0]) { @@ -204,9 +204,9 @@ class FilterBadWord{ } - else if (after[1].match(this.subfilter) != null){ + else if (after[1].match(this._subfilter) != null){ - check_repr = after[1].match(this.subfilter); + check_repr = after[1].match(this._subfilter); if (check_repr != after[1]) { arry.push("Toxic"); @@ -231,7 +231,7 @@ class FilterBadWord{ } catch(err){ - if ( this.word.match(this.filt) != null) { + if ( this._text.match(this._filt) != null) { arry.push("Toxic"); @@ -273,13 +273,13 @@ class FilterBadWord{ var word, process, output, sensore; - word = this.word.split(" "); + word = this._text.split(" "); sensore = "*"; process = position.forEach( number => { - const get_word = this.constructor.getboundPosition(this.word.toString() , number); + const get_word = this.constructor.getboundPosition(this._text.toString() , number); for (var i = 0; i < word.length; i++) { @@ -303,7 +303,7 @@ class FilterBadWord{ //position.forEach( async(number) => { - //const get_word = await this.constructor.getboundPosition(this.word.toString() , number); + //const get_word = await this.constructor.getboundPosition(this._text.toString() , number); //for (var i = 0; i < word.length; i++) { @@ -323,30 +323,30 @@ class FilterBadWord{ class filters_badword extends FilterBadWord{ - ['words_o'](word){ + ['words_o'](text){ - this.word = word.toString(); + this._text = text.toString(); } ['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ - this.cl = cl; - this.st = smart; + this._cl = cl; + this._st = smart; if (customFilter){ - this.filt = new RegExp(this.filt.source+"|"+escapeRegExp(customFilter), "gi"); + this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); }; if (customSubFilter){ - this.subfilter = new RegExp(this.subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); + this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; } get ['cleans'](){ - if (this.cl === true) { + if (this._cl === true) { if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { - if (this.st === true) { + if (this._st === true) { var sensore = "*"; for (var i = 0; i < this.thisToxic[2].length; i++) { @@ -355,18 +355,18 @@ class filters_badword extends FilterBadWord{ }; - return this.clean(this.position()).replace(this.thisToxic[2], sensore); + return this._clean(this.position()).replace(this.thisToxic[2], sensore); }; - return this.clean(this.position()); + return this._clean(this.position()); }; - return this.clean(this.position()); + return this._clean(this.position()); } else{ - return this.word.trim(); + return this._text.trim(); } From d05d81556b18d30b4d68bbe3c875c54f2069e060 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 11:58:05 +0700 Subject: [PATCH 08/44] badword.js --- badword.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/badword.js b/badword.js index 4f774d7..6244694 100644 --- a/badword.js +++ b/badword.js @@ -397,10 +397,7 @@ const exportsObject = { }; // Periksa lingkungan eksekusi -if (typeof exports === 'object' && typeof module !== 'undefined') { - // Ekspor ke Node.js - module.exports = exportsObject; -}else { - // Ekspor ke browser - Object.assign(window, exportsObject); -}; +const isNode = typeof exports === 'object' && typeof module !== 'undefined'; + +// Ekspor ke lingkungan yang sesuai +isNode ? module.exports = exportsObject : Object.assign(window, exportsObject); From c8fd090c4d77737cae74b264bdb17eced20b9ce9 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 12:55:02 +0700 Subject: [PATCH 09/44] README.md --- README.md | 107 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8f8de65..70b01e3 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,102 @@ - +## ๐ŸŽ‰ **Welcome to BadFilter.js!** ๐ŸŽ‰ -```Javascript hl_lines="4 9-12 25-27" +Tired of offensive language in your app? ๐Ÿšซ **BadFilter.js** to the rescue! Weโ€™ve crafted a supercharged, customizable solution that helps developers filter out inappropriate words like a pro. Let's make the internet a friendlier place one word at a time! ๐ŸŒ๐Ÿ’ฌ + +--- + +## ๐Ÿ› ๏ธ **Overview** + +**BadFilter.js** offers two powerful components: +- **FilterBadWord Class**: The brains of the operation! This utility class is responsible for filtering unwanted words from your text. +- **filters_badword Function**: A lightweight wrapper around `FilterBadWord` for easier, more streamlined usage. Think of it as the "express mode" for your text-filtering needs! + +With these components, you can easily cleanse your text, ensuring a respectful, safe online environment. ๐Ÿš€โœจ + +--- + +## ๐Ÿ”ง **How It Works** +Both **FilterBadWord** and **filters_badword** combine Natural Language Processing (NLP) and Machine Learning (ML) for *accurate* and *intelligent* word filtering. + +Here's the breakdown of the magic: +1. **Tokenization**: Your text gets split into individual words (tokens) ๐Ÿงฉ. +2. **NLP Analysis**: The tokens are scanned using cutting-edge NLP algorithms to sniff out those pesky bad words ๐Ÿ•ต๏ธโ€โ™‚๏ธ. +3. **Machine Learning**: Filtering gets smarter with each interaction, ensuring those inappropriate words vanish into thin air โœจ. +4. **Customization**: Want to fine-tune the filter to match your app's personality? You got it! Use the handy config method to tweak things to perfection ๐ŸŽ›๏ธ. + +--- + +## ๐Ÿš€ **Getting Started** + +### 1๏ธโƒฃ **HTML Setup** +Want to use BadFilter.js in your web app? No problem! Hereโ€™s how: +```html + + + + + + +``` +Easy peasy, right? ๐Ÿ‹ + +### 2๏ธโƒฃ **Node.js Setup** +If youโ€™re working on a Node.js project, just use this: +```javascript +const { FilterBadWord, filters_badword } = require('./badword.js'); + +// Express filtering using filters_badword +const badfilter = new FilterBadWord("FUck master"); +console.log(badfilter.clean(badfilter.position())); // Output: ***** master +``` + +### ๐ŸŽฏ **Pro Mode: filters_badword Class** +For full control over filtering, dive into the **filters_badword** class: +```javascript const badfilt = new filters_badword(); -badfilt.config(true, false); //accpet filter and error print -badfilt.words_o("FUck master"); -console.log( badfilt.cleans ); -console.log( badfilt.position() ); -//result ***** master +badfilt.config(true, false); // Custom filtering settings +badfilt.words_o("FUck master"); // Censored output: ***** master +console.log(badfilt.cleans); +console.log(badfilt.position()); // Shows position of the bad word badfilt.words_o("motherfucker"); -console.log( badfilt.cleans ); -console.log( badfilt.position() ); -//result ************* +console.log(badfilt.cleans); // Output: ************* +console.log(badfilt.position()); ``` + +๐Ÿ”ง **Config it your way!** Customize how strict or lenient your filter should be using `.config()`. Want more control? You got it! + +--- + +## ๐Ÿ’ก **Features You'll Love** + +### ๐Ÿง  **Smart Filtering** +Thanks to the NLP + ML combo, your filters get sharper over time, catching even the sneakier bad words. Say goodbye to offensive content! ๐Ÿ™…โ€โ™‚๏ธ๐Ÿšซ + +### ๐ŸŽจ **Fully Customizable** +Want to allow certain words or apply extra strict filtering? Adjust it with ease. Youโ€™re in the driverโ€™s seat of how clean your app should be. Customize the experience and make it yours! ๐Ÿ› ๏ธ + +### โšก **Blazing Fast** +We know speed matters! BadFilter.js is optimized to perform like a ninjaโ€”fast and precise. Your users wonโ€™t even notice the filtering happening in the background. ๐ŸŒช๏ธ + +--- + +## ๐Ÿค” **Why Choose BadFilter.js?** + +- **Accuracy**: Spot-on detection of offensive words using cutting-edge algorithms ๐ŸŽฏ. +- **Customizable**: Shape the filter to match your appโ€™s personality ๐ŸŽ›๏ธ. +- **Safe Spaces**: Build a more positive, respectful community ๐ŸŒธ. + +Whether you're building a chat app, a forum, or an online game, **BadFilter.js** will ensure everyone has a good time without the drama! ๐ŸŽ‰ + +--- + +## ๐ŸŽฌ **Wrap-Up** + +With **BadFilter.js**, you're one step closer to making the internet a more positive place. Say goodbye to offensive language and hello to a world of friendly interactions. Let's get filtering, and have some fun while we're at it! โœจ + +Go on, give it a spin and watch the magic unfold in your app! ๐Ÿš€ From f37270ebee5f171e421fed6660a42e7566cd04e7 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:17:44 +0700 Subject: [PATCH 10/44] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70b01e3..76a2bb5 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ badfilt.words_o("FUck master"); // Censored output: ***** master console.log(badfilt.cleans); console.log(badfilt.position()); // Shows position of the bad word -badfilt.words_o("motherfucker"); +badfilt.text_o("motherfucker"); console.log(badfilt.cleans); // Output: ************* console.log(badfilt.position()); ``` From 357d796b2ceba6c72ff245416f79e2e2c0db3b8d Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:21:51 +0700 Subject: [PATCH 11/44] badword.js --- badword.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/badword.js b/badword.js index 6244694..076d519 100644 --- a/badword.js +++ b/badword.js @@ -323,7 +323,7 @@ class FilterBadWord{ class filters_badword extends FilterBadWord{ - ['words_o'](text){ + ['text_o'](text){ this._text = text.toString(); From 99e8f1ab335202334dc44f2032cacae480875c4f Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:22:39 +0700 Subject: [PATCH 12/44] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 76a2bb5..a9e9321 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ For full control over filtering, dive into the **filters_badword** class: ```javascript const badfilt = new filters_badword(); badfilt.config(true, false); // Custom filtering settings -badfilt.words_o("FUck master"); // Censored output: ***** master +badfilt.text_o("FUck master"); // Censored output: ***** master console.log(badfilt.cleans); console.log(badfilt.position()); // Shows position of the bad word From 9ecf5b4488fa1c89a637273b8fe9e4c3a86c420e Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:33:24 +0700 Subject: [PATCH 13/44] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9e9321..871e2f8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Tired of offensive language in your app? ๐Ÿšซ **BadFilter.js** to the rescue! We **BadFilter.js** offers two powerful components: - **FilterBadWord Class**: The brains of the operation! This utility class is responsible for filtering unwanted words from your text. -- **filters_badword Function**: A lightweight wrapper around `FilterBadWord` for easier, more streamlined usage. Think of it as the "express mode" for your text-filtering needs! +- **filters_badword Class**: A lightweight wrapper around `FilterBadWord` for easier, more streamlined usage. Think of it as the "express mode" for your text-filtering needs! With these components, you can easily cleanse your text, ensuring a respectful, safe online environment. ๐Ÿš€โœจ From 38eac9fdff97153bf124a1b6c5b88821376c398c Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 14:21:46 +0700 Subject: [PATCH 14/44] badword.js --- badword.js | 295 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 182 insertions(+), 113 deletions(-) diff --git a/badword.js b/badword.js index 076d519..45aa03f 100644 --- a/badword.js +++ b/badword.js @@ -1,3 +1,47 @@ +/** + * Fungsi untuk memeriksa apakah kata cocok dengan pola regex + * @param {string} word - string kata yang akan diperiksa + * @param {regex} regex - pola regex yang akan digunakan untuk memeriksa kata-kata + * @return {boolean} - true jika kata cocok dengan pola regex, false jika tidak + */ +function RegexMatch(word, regex) { + const words = word.trim(); + let barisdata = []; + if (words){ + for (let index = 0; index < words.length; index++) { + let datacocok = barisdata.join("").toLowerCase(); + if (datacocok.match(regex)){ + return true; + }else{ + if (datacocok.replace(/1/gi, "i").match(regex)){ + return true; + }else if (datacocok.replace(/1/gi, "l").match(regex)){ + return true; + }else if (datacocok.replace(/6/gi, "b").match(regex)){ + return true; + }else if (datacocok.replace(/6/gi, "g").match(regex)){ + return true; + }; + + if (words[index].indexOf("3")){ + words[index] = "e"; + }else if(words[index].indexOf("0")){ + words[index] = "o"; + }else if(words[index].indexOf("4")){ + words[index] = "a"; + }else if(words[index].indexOf("5")){ + words[index] = "s"; + }else if(words[index].indexOf("8")){ + words[index] = "b"; + }; + }; + barisdata.push(words[index].trim()); + }; + }; + // Return array baris yang cocok + return false; +}; + function escapeRegExp(strings){ let data = strings.trim().toLowerCase().split("|").filter(Boolean); for (let index = 0; index < data.length; index++) { @@ -14,15 +58,35 @@ function escapeRegExp(strings){ return data.source; }; +function validateInput(type, value) { + let regex; + switch (type) { + case 'email': + // Regex kompleks untuk email + regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$/; + break; + case 'phone': + // Regex kompleks untuk nomor telepon (contoh: +1-234-567-8900, (123) 456-7890, 123-456-7890, 1234567890) + regex = /^(?:\+?(\d{1,3}))?[-. ]?(\(?\d{1,4}?\)?)[-.\s]?(\d{1,4})[-.\s]?(\d{1,4})[-.\s]?(\d{1,9})$/; + break; + case 'url': + // Regex kompleks untuk URL + regex = /^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.[a-zA-Z]{2,})(\/[^\s]*)?$/; + break; + default: + return false; // Tipe tidak valid + } + return regex.test(value); +}; class FilterBadWord{ - constructor(text = "", customFilter="", customSubFilter=""){ +constructor(text = "", customFilter="", customSubFilter=""){ this._text = text; this._filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|fk/gi; - + this._clear = false; this._subfilter = /[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|[s5]uck[*]?|m[o0]th[e3]r[*]?|m[o0]m[*]?|d[o0]g[*]?|l[o0]w[*]?|s[e3]x[*]?/gi; if (customFilter){ this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); @@ -30,12 +94,11 @@ class FilterBadWord{ if (customSubFilter){ this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; - } - +} - static getboundPosition(word, _position){ - +static getboundPosition(word, _position){ + var paragap, end; paragap = word; @@ -53,11 +116,11 @@ class FilterBadWord{ } return paragap.substring(_position, end); - } +} - static ['position_static'](word, filters){ - +static ['position_static'](word, filters){ + var wordlist_, filt, result, json_, position_; @@ -68,7 +131,7 @@ class FilterBadWord{ json_ = wordlist_.map( (word, index) => { position_ = index&&wordlist_[index - 1].length+position_+1; - + return {word, position_} }); @@ -80,33 +143,40 @@ class FilterBadWord{ wordlist_ = json_[i].word.match(filters); if (wordlist_ != null || wordlist_ === 0 ) { - + position_.push(json_[i].position_); + }else{ + + wordlist_ = RegexMatch(json_[i].word, filters); + if (wordlist_ != false) { + position_.push(json_[i].position_); + }; + } }; - + return position_; - } +} - ['position']() { - //if ( typeof position != "number" ) { - //position = parseInt(position); - //} - this.positionList = this.constructor.position_static(this._text.toString(), this._filt); - - return this.positionList; +['position']() { - } + var positionList = this.constructor.position_static(this._text.toString(), this._filt); - get ['thisToxic'](){ - + return positionList; + +} + +get ['thisToxic'](){ + var check = this.position(); var after ="", before ="", check_repr =""; + var arry = []; + if (check != null || check != 0) { var word = this._text.toLowerCase(); @@ -115,12 +185,12 @@ class FilterBadWord{ return word.substring(number, word.indexOf(key));//nomer dan keyword - } - - function after_Str(w, spec){ + }; - return word.substring( word.indexOf(w), spec.length+word.length ).replace(w, "").trim(); //, word.indexOf(spec)); - } + function after_str(w, spec){ + let data =word.substring( word.indexOf(w), spec.length+word.length ); + return data.replace(w, "").trim(); //, word.indexOf(spec)); + }; for (var i = 0; i < check.length; i++) { @@ -128,7 +198,7 @@ class FilterBadWord{ before = before_str(0 , word_s).toString().split(" "); - after = after_Str(word_s, this._text).toString().split(" "); + after = after_str(word_s, this._text).toString().split(" "); //console.log(word.indexOf(word_s)); if (after.length >= 1 ){ @@ -141,7 +211,7 @@ class FilterBadWord{ }); - } + }; //console.log(word.substring(word.indexOf(word_s)) ) if (before[before.length-1] === ""){ @@ -154,8 +224,32 @@ class FilterBadWord{ }); - } - + }; + //ambil kata sebelum dan sesudah; + //console.log(before, after); + if (before){ + before.forEach(d=>{ + + if (d.match(this._subfilter)){ + + this._text = this._text.replace(d, '*'.repeat(d.length)); + + }; + + }); + }; + if (after){ + after.forEach(d=>{ + + if (d.match(this._subfilter)){ + + this._text = this._text.replace(d, '*'.repeat(d.length)); + + }; + + }); + }; + try{ if (before[before.length-1].match(this._subfilter) != null) { @@ -209,6 +303,7 @@ class FilterBadWord{ check_repr = after[1].match(this._subfilter); if (check_repr != after[1]) { + arry.push("Toxic"); arry.push(1); break @@ -234,23 +329,17 @@ class FilterBadWord{ if ( this._text.match(this._filt) != null) { arry.push("Toxic"); - arry.push(1); - break; }; - } - - }; if (arry.length <= 1) { arry.push("Notoxic"); - arry.push(0); }; @@ -261,38 +350,31 @@ class FilterBadWord{ }; return false; - } +} - set ['thisToxic'](key){ - - throw key; +set ['thisToxic'](key){ - } + throw key; + +} - ['clean'](position){ +['clean'](position){ - var word, process, output, sensore; + var word, output; word = this._text.split(" "); - sensore = "*"; - process = position.forEach( number => { + position.forEach( number => { const get_word = this.constructor.getboundPosition(this._text.toString() , number); - for (var i = 0; i < word.length; i++) { + for (var i = 0; i < word.length-1; i++) { + if (this._clear || !(validateInput("email", word[i]) || validateInput("url", word[i]))){ - for (var x = 0; x < get_word.length; x++) { - - sensore += "*"; + word[i] = word[i].replace(get_word, '*'.repeat(get_word.length)); }; - - word[i] = word[i].replace(get_word, sensore); - - sensore = "*"; - }; }); @@ -301,85 +383,72 @@ class FilterBadWord{ return output.join(" "); - //position.forEach( async(number) => { - - //const get_word = await this.constructor.getboundPosition(this._text.toString() , number); - - //for (var i = 0; i < word.length; i++) { - - //word[i] = word[i].replace(get_word, "**"); - - //}; +} - //console.log(word); +}; - //}); - - } +class filters_badword extends FilterBadWord{ + +['text_o'](text){ + + this._text = text.toString(); } +['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ + this._cl = cl; + this._st = smart; + this._clear = smart ? false : true; + if (customFilter){ + this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); + }; + if (customSubFilter){ + this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); + }; +} -class filters_badword extends FilterBadWord{ +get ['cleans'](){ - ['text_o'](text){ + if (this._cl === true) { - this._text = text.toString(); - - } + if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { - ['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ - this._cl = cl; - this._st = smart; - if (customFilter){ - this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); - }; - if (customSubFilter){ - this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); - }; - } - - get ['cleans'](){ + if (this._st === true) { + var sensore = "*"; - if (this._cl === true) { + for (var i = 0; i < this.thisToxic[2].length; i++) { - if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { - - if (this._st === true) { - var sensore = "*"; - - for (var i = 0; i < this.thisToxic[2].length; i++) { - - sensore += "*"; - - }; - - return this._clean(this.position()).replace(this.thisToxic[2], sensore); - }; - return this._clean(this.position()); - + sensore += "*"; + + }; + return this.clean(this.position()).replace(this.thisToxic[2], sensore); }; + + return this.clean(this.position()); - return this._clean(this.position()); - - } - else{ - - return this._text.trim(); + }; - } + return this.clean(this.position()); } - - set ['cleans'](value){ + else{ - throw value; + return this._text.trim(); - } + }; + +} + +set ['cleans'](value){ + + throw value; + +} }; + // Definisikan objek ekspor const exportsObject = { /** From a62917438d8d9d8166b1a2c464a1d543575db184 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 14:42:07 +0700 Subject: [PATCH 15/44] badword.js --- badword.js | 279 ++++++++++++++++++++++------------------------------- 1 file changed, 116 insertions(+), 163 deletions(-) diff --git a/badword.js b/badword.js index 45aa03f..d6b58a4 100644 --- a/badword.js +++ b/badword.js @@ -1,47 +1,3 @@ -/** - * Fungsi untuk memeriksa apakah kata cocok dengan pola regex - * @param {string} word - string kata yang akan diperiksa - * @param {regex} regex - pola regex yang akan digunakan untuk memeriksa kata-kata - * @return {boolean} - true jika kata cocok dengan pola regex, false jika tidak - */ -function RegexMatch(word, regex) { - const words = word.trim(); - let barisdata = []; - if (words){ - for (let index = 0; index < words.length; index++) { - let datacocok = barisdata.join("").toLowerCase(); - if (datacocok.match(regex)){ - return true; - }else{ - if (datacocok.replace(/1/gi, "i").match(regex)){ - return true; - }else if (datacocok.replace(/1/gi, "l").match(regex)){ - return true; - }else if (datacocok.replace(/6/gi, "b").match(regex)){ - return true; - }else if (datacocok.replace(/6/gi, "g").match(regex)){ - return true; - }; - - if (words[index].indexOf("3")){ - words[index] = "e"; - }else if(words[index].indexOf("0")){ - words[index] = "o"; - }else if(words[index].indexOf("4")){ - words[index] = "a"; - }else if(words[index].indexOf("5")){ - words[index] = "s"; - }else if(words[index].indexOf("8")){ - words[index] = "b"; - }; - }; - barisdata.push(words[index].trim()); - }; - }; - // Return array baris yang cocok - return false; -}; - function escapeRegExp(strings){ let data = strings.trim().toLowerCase().split("|").filter(Boolean); for (let index = 0; index < data.length; index++) { @@ -81,12 +37,12 @@ function validateInput(type, value) { class FilterBadWord{ -constructor(text = "", customFilter="", customSubFilter=""){ + constructor(text = "", customFilter="", customSubFilter=""){ this._text = text; - - this._filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|fk/gi; this._clear = false; + this._filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|fk/gi; + this._subfilter = /[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|[s5]uck[*]?|m[o0]th[e3]r[*]?|m[o0]m[*]?|d[o0]g[*]?|l[o0]w[*]?|s[e3]x[*]?/gi; if (customFilter){ this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); @@ -94,11 +50,12 @@ constructor(text = "", customFilter="", customSubFilter=""){ if (customSubFilter){ this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; -} + } -static getboundPosition(word, _position){ - + + static getboundPosition(word, _position){ + var paragap, end; paragap = word; @@ -116,11 +73,11 @@ static getboundPosition(word, _position){ } return paragap.substring(_position, end); -} + } -static ['position_static'](word, filters){ - + static ['position_static'](word, filters){ + var wordlist_, filt, result, json_, position_; @@ -131,7 +88,7 @@ static ['position_static'](word, filters){ json_ = wordlist_.map( (word, index) => { position_ = index&&wordlist_[index - 1].length+position_+1; - + return {word, position_} }); @@ -143,40 +100,33 @@ static ['position_static'](word, filters){ wordlist_ = json_[i].word.match(filters); if (wordlist_ != null || wordlist_ === 0 ) { - + position_.push(json_[i].position_); - }else{ - - wordlist_ = RegexMatch(json_[i].word, filters); - if (wordlist_ != false) { - position_.push(json_[i].position_); - }; - } }; - + return position_; -} + } -['position']() { + ['position']() { + //if ( typeof position != "number" ) { + //position = parseInt(position); + //} + this.positionList = this.constructor.position_static(this._text.toString(), this._filt); - var positionList = this.constructor.position_static(this._text.toString(), this._filt); - - return positionList; - -} - -get ['thisToxic'](){ + return this.positionList; + } + + get ['thisToxic'](){ + var check = this.position(); var after ="", before ="", check_repr =""; - var arry = []; - if (check != null || check != 0) { var word = this._text.toLowerCase(); @@ -185,12 +135,12 @@ get ['thisToxic'](){ return word.substring(number, word.indexOf(key));//nomer dan keyword - }; + } - function after_str(w, spec){ - let data =word.substring( word.indexOf(w), spec.length+word.length ); - return data.replace(w, "").trim(); //, word.indexOf(spec)); - }; + function after_Str(w, spec){ + + return word.substring( word.indexOf(w), spec.length+word.length ).replace(w, "").trim(); //, word.indexOf(spec)); + } for (var i = 0; i < check.length; i++) { @@ -198,7 +148,7 @@ get ['thisToxic'](){ before = before_str(0 , word_s).toString().split(" "); - after = after_str(word_s, this._text).toString().split(" "); + after = after_Str(word_s, this._text).toString().split(" "); //console.log(word.indexOf(word_s)); if (after.length >= 1 ){ @@ -211,7 +161,7 @@ get ['thisToxic'](){ }); - }; + } //console.log(word.substring(word.indexOf(word_s)) ) if (before[before.length-1] === ""){ @@ -224,32 +174,8 @@ get ['thisToxic'](){ }); - }; - //ambil kata sebelum dan sesudah; - //console.log(before, after); - if (before){ - before.forEach(d=>{ - - if (d.match(this._subfilter)){ - - this._text = this._text.replace(d, '*'.repeat(d.length)); - - }; - - }); - }; - if (after){ - after.forEach(d=>{ - - if (d.match(this._subfilter)){ - - this._text = this._text.replace(d, '*'.repeat(d.length)); - - }; - - }); - }; - + } + try{ if (before[before.length-1].match(this._subfilter) != null) { @@ -303,7 +229,6 @@ get ['thisToxic'](){ check_repr = after[1].match(this._subfilter); if (check_repr != after[1]) { - arry.push("Toxic"); arry.push(1); break @@ -329,17 +254,23 @@ get ['thisToxic'](){ if ( this._text.match(this._filt) != null) { arry.push("Toxic"); + arry.push(1); + break; }; + } + + }; if (arry.length <= 1) { arry.push("Notoxic"); + arry.push(0); }; @@ -350,31 +281,39 @@ get ['thisToxic'](){ }; return false; -} + } -set ['thisToxic'](key){ - + set ['thisToxic'](key){ + throw key; + + } -} - -['clean'](position){ + ['clean'](position){ - var word, output; + var word, process, output, sensore; word = this._text.split(" "); + sensore = "*"; - position.forEach( number => { + process = position.forEach( number => { const get_word = this.constructor.getboundPosition(this._text.toString() , number); - for (var i = 0; i < word.length-1; i++) { - if (this._clear || !(validateInput("email", word[i]) || validateInput("url", word[i]))){ + for (var i = 0; i < word.length; i++) { - word[i] = word[i].replace(get_word, '*'.repeat(get_word.length)); + for (var x = 0; x < get_word.length; x++) { + + sensore += "*"; }; + + if (this._clear || (!validateInput("email", word[i]) && !validateInput("url", word[i]))){ + word[i] = word[i].replace(get_word, sensore); + }; + sensore = "*"; + }; }); @@ -383,72 +322,86 @@ set ['thisToxic'](key){ return output.join(" "); -} - -}; + //position.forEach( async(number) => { + + //const get_word = await this.constructor.getboundPosition(this._text.toString() , number); + + //for (var i = 0; i < word.length; i++) { + + //word[i] = word[i].replace(get_word, "**"); + + //}; + //console.log(word); -class filters_badword extends FilterBadWord{ + //}); -['text_o'](text){ - - this._text = text.toString(); + + } } -['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ - this._cl = cl; - this._st = smart; - this._clear = smart ? false : true; - if (customFilter){ - this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); - }; - if (customSubFilter){ - this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); - }; -} -get ['cleans'](){ +class filters_badword extends FilterBadWord{ - if (this._cl === true) { + ['text_o'](text){ - if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { + this._text = text.toString(); + + } - if (this._st === true) { - var sensore = "*"; - - for (var i = 0; i < this.thisToxic[2].length; i++) { + ['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ + this._cl = cl; + this._st = smart; + this._clear = smart ? false : true; + if (customFilter){ + this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); + }; + if (customSubFilter){ + this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); + }; + } + + get ['cleans'](){ - sensore += "*"; + if (this._cl === true) { - }; - return this.clean(this.position()).replace(this.thisToxic[2], sensore); - }; + if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { + + if (this._st === true) { + var sensore = "*"; - return this.clean(this.position()); + for (var i = 0; i < this.thisToxic[2].length; i++) { + + sensore += "*"; + + }; - }; - - return this.clean(this.position()); + return this._clean(this.position()).replace(this.thisToxic[2], sensore); + }; + return this._clean(this.position()); - } - else{ + }; + + return this._clean(this.position()); + + } + else{ + + return this._text.trim(); - return this._text.trim(); - - }; + } -} + } -set ['cleans'](value){ + set ['cleans'](value){ + + throw value; - throw value; - -} + } }; - // Definisikan objek ekspor const exportsObject = { /** From 0d734a71f4cfaff96391b9ca6aa99dc9c4730f0e Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 14:53:03 +0700 Subject: [PATCH 16/44] badword.js --- badword.js | 226 +++++++++++++++++++++++++---------------------------- 1 file changed, 108 insertions(+), 118 deletions(-) diff --git a/badword.js b/badword.js index d6b58a4..5c31ae3 100644 --- a/badword.js +++ b/badword.js @@ -37,10 +37,10 @@ function validateInput(type, value) { class FilterBadWord{ - constructor(text = "", customFilter="", customSubFilter=""){ +constructor(text= "", customFilter="", customSubFilter=""){ this._text = text; - this._clear = false; + this._filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|fk/gi; this._subfilter = /[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|[s5]uck[*]?|m[o0]th[e3]r[*]?|m[o0]m[*]?|d[o0]g[*]?|l[o0]w[*]?|s[e3]x[*]?/gi; @@ -50,12 +50,11 @@ class FilterBadWord{ if (customSubFilter){ this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; - } - +} - static getboundPosition(word, _position){ - +static getboundPosition(word, _position){ + var paragap, end; paragap = word; @@ -73,11 +72,11 @@ class FilterBadWord{ } return paragap.substring(_position, end); - } +} - static ['position_static'](word, filters){ - +static ['position_static'](word, filters){ + var wordlist_, filt, result, json_, position_; @@ -88,7 +87,7 @@ class FilterBadWord{ json_ = wordlist_.map( (word, index) => { position_ = index&&wordlist_[index - 1].length+position_+1; - + return {word, position_} }); @@ -100,33 +99,33 @@ class FilterBadWord{ wordlist_ = json_[i].word.match(filters); if (wordlist_ != null || wordlist_ === 0 ) { - - position_.push(json_[i].position_); + + position_.push(json_[i].position_); - } + }; }; - + return position_; - } +} - ['position']() { - //if ( typeof position != "number" ) { - //position = parseInt(position); - //} - this.positionList = this.constructor.position_static(this._text.toString(), this._filt); +['position']() { - return this.positionList; - - } + var positionList = this.constructor.position_static(this._text.toString(), this._filt); - get ['thisToxic'](){ - + return positionList; + +} + +get ['thisToxic'](){ + var check = this.position(); var after ="", before ="", check_repr =""; + var arry = []; + if (check != null || check != 0) { var word = this._text.toLowerCase(); @@ -135,12 +134,12 @@ class FilterBadWord{ return word.substring(number, word.indexOf(key));//nomer dan keyword - } - - function after_Str(w, spec){ + }; - return word.substring( word.indexOf(w), spec.length+word.length ).replace(w, "").trim(); //, word.indexOf(spec)); - } + function after_str(w, spec){ + let data =word.substring( word.indexOf(w), spec.length+word.length ); + return data.replace(w, "").trim(); //, word.indexOf(spec)); + }; for (var i = 0; i < check.length; i++) { @@ -148,7 +147,7 @@ class FilterBadWord{ before = before_str(0 , word_s).toString().split(" "); - after = after_Str(word_s, this._text).toString().split(" "); + after = after_str(word_s, this._text).toString().split(" "); //console.log(word.indexOf(word_s)); if (after.length >= 1 ){ @@ -174,8 +173,31 @@ class FilterBadWord{ }); - } - + }; + //ambil kata sebelum dan sesudah; + //console.log(before, after); + if (before){ + before.forEach(d=>{ + + if (d.match(this._subfilter)){ + + this._text = this._text.replace(d, '*'.repeat(d.length)); + + }; + + }); + }; + if (after){ + after.forEach(d=>{ + + if (d.match(this._subfilter)){ + + this._text = this._text.replace(d, '*'.repeat(d.length)); + + }; + + }); + }; try{ if (before[before.length-1].match(this._subfilter) != null) { @@ -229,6 +251,7 @@ class FilterBadWord{ check_repr = after[1].match(this._subfilter); if (check_repr != after[1]) { + arry.push("Toxic"); arry.push(1); break @@ -254,23 +277,17 @@ class FilterBadWord{ if ( this._text.match(this._filt) != null) { arry.push("Toxic"); - arry.push(1); - break; }; - } - - }; if (arry.length <= 1) { arry.push("Notoxic"); - arry.push(0); }; @@ -281,39 +298,29 @@ class FilterBadWord{ }; return false; - } +} - set ['thisToxic'](key){ - - throw key; +set ['thisToxic'](key){ - } + throw key; - ['clean'](position){ +} + +['clean'](position){ - var word, process, output, sensore; + var word, process, output; word = this._text.split(" "); - sensore = "*"; - process = position.forEach( number => { + position.forEach( number => { const get_word = this.constructor.getboundPosition(this._text.toString() , number); - for (var i = 0; i < word.length; i++) { - - for (var x = 0; x < get_word.length; x++) { - - sensore += "*"; - - }; - - if (this._clear || (!validateInput("email", word[i]) && !validateInput("url", word[i]))){ - word[i] = word[i].replace(get_word, sensore); + for (var i = 0; i < word.length-1; i++) { + if ((!validateInput("email", word[i]) && !validateInput("url", word[i]))){ + word[i] = word[i].replace(get_word, '*'.repeat(get_word.length)); }; - sensore = "*"; - }; }); @@ -322,86 +329,69 @@ class FilterBadWord{ return output.join(" "); - //position.forEach( async(number) => { - - //const get_word = await this.constructor.getboundPosition(this._text.toString() , number); - - //for (var i = 0; i < word.length; i++) { - - //word[i] = word[i].replace(get_word, "**"); - - //}; +} - //console.log(word); +} - //}); - - } +class filters_badword extends FilterBadWord{ + +['text_o'](text){ + + this._text = text.toString(); } +['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ + this._cl = cl; + this._st = smart; + if (customFilter){ + this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); + }; + if (customSubFilter){ + this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); + }; +} -class filters_badword extends FilterBadWord{ +get ['cleans'](){ - ['text_o'](text){ - - this._text = text.toString(); + if (this._cl === true) { - } + if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { - ['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ - this._cl = cl; - this._st = smart; - this._clear = smart ? false : true; - if (customFilter){ - this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); - }; - if (customSubFilter){ - this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); - }; - } - - get ['cleans'](){ + if (this._st === true) { + var sensore = "*"; - if (this._cl === true) { + for (var i = 0; i < this.thisToxic[2].length; i++) { - if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { - - if (this._st === true) { - var sensore = "*"; - - for (var i = 0; i < this.thisToxic[2].length; i++) { - - sensore += "*"; - - }; - - return this._clean(this.position()).replace(this.thisToxic[2], sensore); - }; - return this._clean(this.position()); - + sensore += "*"; + + }; + return this.clean(this.position()).replace(this.thisToxic[2], sensore); }; + + return this.clean(this.position()); - return this._clean(this.position()); - - } - else{ - - return this._text.trim(); + }; - } + return this.clean(this.position()); } - - set ['cleans'](value){ + else{ - throw value; + return this._text.trim(); } -}; +} + +set ['cleans'](value){ + + throw value; +} + +}; // Definisikan objek ekspor const exportsObject = { /** From c02537bba86af709f1ff0edb19dcc6a11c3c3748 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:02:40 +0700 Subject: [PATCH 17/44] badword.js --- badword.js | 250 +++++++++++++++++++++++++++-------------------------- 1 file changed, 129 insertions(+), 121 deletions(-) diff --git a/badword.js b/badword.js index 5c31ae3..faf3b1a 100644 --- a/badword.js +++ b/badword.js @@ -14,12 +14,13 @@ function escapeRegExp(strings){ return data.source; }; + function validateInput(type, value) { let regex; switch (type) { case 'email': // Regex kompleks untuk email - regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$/; + regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(com|net|org|edu|gov|mil|co|info|io|biz|id|us|uk|ca|au|de|fr|es|it|jp|cn|br|in|ru|mx|kr|za|nl|se|no|fi|dk|pl|pt|ar|ch|hk|sg|my|th|vn|ae|at|be|cz|hu|ro|bg|gr|lt|lv|sk|si|ee|cy)(\.[a-zA-Z]{2,})?$/; break; case 'phone': // Regex kompleks untuk nomor telepon (contoh: +1-234-567-8900, (123) 456-7890, 123-456-7890, 1234567890) @@ -34,27 +35,26 @@ function validateInput(type, value) { } return regex.test(value); }; - class FilterBadWord{ -constructor(text= "", customFilter="", customSubFilter=""){ - - this._text = text; + constructor(word = "", customFilter="", customSubFilter=""){ + + this.word = word; - this._filt = /b[a4][s5]hfu[l1][l1]|k[i1][l1][l1]|fuck[*]?|dr[uo]g[*]?|d[i1]ck[*]?|fk/gi; + this.filt = /[b8][[a4][s5]hfu[l1][l1]*|k[i1][l1][l1]*|fuck*|dr[uo]g*|d[i1]ck*|fk/gi; - this._subfilter = /[a4][s5][s5]|[l1][i1]p|pu[s5][s5]y[*]?|[s5]uck[*]?|m[o0]th[e3]r[*]?|m[o0]m[*]?|d[o0]g[*]?|l[o0]w[*]?|s[e3]x[*]?/gi; + this.subfilter = /ass|lip|pussy*|suck*|mother*|mom*|dog*|low*|sex*/gi; if (customFilter){ this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); }; if (customSubFilter){ this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; -} + } -static getboundPosition(word, _position){ - + static getboundPosition(word, _position){ + var paragap, end; paragap = word; @@ -72,11 +72,11 @@ static getboundPosition(word, _position){ } return paragap.substring(_position, end); -} + } -static ['position_static'](word, filters){ - + static ['position_static'](word, filters){ + var wordlist_, filt, result, json_, position_; @@ -87,7 +87,7 @@ static ['position_static'](word, filters){ json_ = wordlist_.map( (word, index) => { position_ = index&&wordlist_[index - 1].length+position_+1; - + return {word, position_} }); @@ -99,55 +99,61 @@ static ['position_static'](word, filters){ wordlist_ = json_[i].word.match(filters); if (wordlist_ != null || wordlist_ === 0 ) { - - position_.push(json_[i].position_); + + position_.push(json_[i].position_); - }; + } }; - + return position_; -} + } -['position']() { + ['position']() { + //if ( typeof position != "number" ) { + //position = parseInt(position); + //} + this.positionList = this.constructor.position_static(this.word.toString(), this.filt); - var positionList = this.constructor.position_static(this._text.toString(), this._filt); - - return positionList; - -} - -get ['thisToxic'](){ + return this.positionList; + } + + get ['thisToxic'](){ + var check = this.position(); - var after ="", before ="", check_repr =""; + var after = ""; + + var before = ""; var arry = []; + + var check_repr = ""; if (check != null || check != 0) { - var word = this._text.toLowerCase(); + var word = this.word.toLowerCase(); function before_str(number , key){ return word.substring(number, word.indexOf(key));//nomer dan keyword - }; + } - function after_str(w, spec){ - let data =word.substring( word.indexOf(w), spec.length+word.length ); - return data.replace(w, "").trim(); //, word.indexOf(spec)); - }; + function after_Str(w, spec){ + + return word.substring( word.indexOf(w), spec.length+word.length ).replace(w, "").trim(); //, word.indexOf(spec)); + } for (var i = 0; i < check.length; i++) { - const word_s = this.constructor.getboundPosition(this._text.toLowerCase().toString() , check[i]); + const word_s = this.constructor.getboundPosition(this.word.toLowerCase().toString() , check[i]); before = before_str(0 , word_s).toString().split(" "); - after = after_str(word_s, this._text).toString().split(" "); + after = after_Str(word_s, this.word).toString().split(" "); //console.log(word.indexOf(word_s)); if (after.length >= 1 ){ @@ -173,36 +179,13 @@ get ['thisToxic'](){ }); - }; - //ambil kata sebelum dan sesudah; - //console.log(before, after); - if (before){ - before.forEach(d=>{ - - if (d.match(this._subfilter)){ - - this._text = this._text.replace(d, '*'.repeat(d.length)); - - }; - - }); - }; - if (after){ - after.forEach(d=>{ - - if (d.match(this._subfilter)){ - - this._text = this._text.replace(d, '*'.repeat(d.length)); - - }; - - }); - }; + } + try{ - if (before[before.length-1].match(this._subfilter) != null) { + if (before[before.length-1].match(this.subfilter) != null) { - check_repr = before[before.length-1].match(this._subfilter); + check_repr = before[before.length-1].match(this.subfilter); if (check_repr != before[before.length-1]) { //check ulang jika sensore tidak memenuhi persyaratan @@ -223,9 +206,9 @@ get ['thisToxic'](){ } - else if (after[0].match(this._subfilter) != null){ + else if (after[0].match(this.subfilter) != null){ - check_repr = after[0].match(this._subfilter); + check_repr = after[0].match(this.subfilter); if (check_repr != after[0]) { @@ -246,12 +229,11 @@ get ['thisToxic'](){ } - else if (after[1].match(this._subfilter) != null){ + else if (after[1].match(this.subfilter) != null){ - check_repr = after[1].match(this._subfilter); + check_repr = after[1].match(this.subfilter); if (check_repr != after[1]) { - arry.push("Toxic"); arry.push(1); break @@ -274,20 +256,26 @@ get ['thisToxic'](){ } catch(err){ - if ( this._text.match(this._filt) != null) { + if ( this.word.match(this.filt) != null) { arry.push("Toxic"); + arry.push(1); + break; }; + } + + }; if (arry.length <= 1) { arry.push("Notoxic"); + arry.push(0); }; @@ -298,29 +286,38 @@ get ['thisToxic'](){ }; return false; -} + } -set ['thisToxic'](key){ - + set ['thisToxic'](key){ + throw key; + + } -} + ['clean'](position){ -['clean'](position){ + var word, process, output, sensore; - var word, process, output; + word = this.word.split(" "); - word = this._text.split(" "); + sensore = "*"; + process = position.forEach( number => { - position.forEach( number => { + const get_word = this.constructor.getboundPosition(this.word.toString() , number); - const get_word = this.constructor.getboundPosition(this._text.toString() , number); + for (var i = 0; i < word.length; i++) { - for (var i = 0; i < word.length-1; i++) { - if ((!validateInput("email", word[i]) && !validateInput("url", word[i]))){ - word[i] = word[i].replace(get_word, '*'.repeat(get_word.length)); + for (var x = 0; x < get_word.length-1; x++) { + + sensore += "*"; + }; + + if (!(validateInput("email", word[i]) || validateInput("url", word[i]))) word[i] = word[i].replace(get_word, sensore); + + sensore = "*"; + }; }); @@ -329,68 +326,79 @@ set ['thisToxic'](key){ return output.join(" "); -} - -} + //position.forEach( async(number) => { + + //const get_word = await this.constructor.getboundPosition(this.word.toString() , number); + + //for (var i = 0; i < word.length; i++) { + + //word[i] = word[i].replace(get_word, "**"); + + //}; + //console.log(word); -class filters_badword extends FilterBadWord{ + //}); -['text_o'](text){ - - this._text = text.toString(); + + } } -['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ - this._cl = cl; - this._st = smart; - if (customFilter){ - this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); - }; - if (customSubFilter){ - this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); - }; -} -get ['cleans'](){ +class filters_badword extends FilterBadWord{ - if (this._cl === true) { + ['words_o'](word){ + + this.word = word.toString(); - if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { + } - if (this._st === true) { - var sensore = "*"; - - for (var i = 0; i < this.thisToxic[2].length; i++) { + ['config'](cl=true, smart=true, er=false){ + + this.cl = cl; + this.st = smart; + this.er = er; + } + + get ['cleans'](){ - sensore += "*"; + if (this.cl === true) { - }; - return this.clean(this.position()).replace(this.thisToxic[2], sensore); - }; + if (this.thisToxic[1] === 1 && this.thisToxic.length > 2 ) { + + if (this.st === true) { + var sensore = "*"; + for (var i = 0; i < this.thisToxic[2].length; i++) { + + sensore += "*"; + + }; + + return this.clean(this.position()).replace(this.thisToxic[2], sensore); + }; + return this.clean(this.position()); + + }; + return this.clean(this.position()); - }; + } + else{ + + return this.word.trim(); - return this.clean(this.position()); + } } - else{ + + set ['cleans'](value){ - return this._text.trim(); + throw value; } -} - -set ['cleans'](value){ - - throw value; - -} - }; // Definisikan objek ekspor const exportsObject = { From 0057e67263072ab3579be9cfc6b8b7613a1329e8 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:05:42 +0700 Subject: [PATCH 18/44] badword.js --- badword.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/badword.js b/badword.js index faf3b1a..3e13434 100644 --- a/badword.js +++ b/badword.js @@ -37,9 +37,9 @@ function validateInput(type, value) { }; class FilterBadWord{ - constructor(word = "", customFilter="", customSubFilter=""){ + constructor(text = "", customFilter="", customSubFilter=""){ - this.word = word; + this.text = text; this.filt = /[b8][[a4][s5]hfu[l1][l1]*|k[i1][l1][l1]*|fuck*|dr[uo]g*|d[i1]ck*|fk/gi; @@ -114,7 +114,7 @@ class FilterBadWord{ //if ( typeof position != "number" ) { //position = parseInt(position); //} - this.positionList = this.constructor.position_static(this.word.toString(), this.filt); + this.positionList = this.constructor.position_static(this.text.toString(), this.filt); return this.positionList; @@ -134,7 +134,7 @@ class FilterBadWord{ if (check != null || check != 0) { - var word = this.word.toLowerCase(); + var word = this.text.toLowerCase(); function before_str(number , key){ @@ -149,11 +149,11 @@ class FilterBadWord{ for (var i = 0; i < check.length; i++) { - const word_s = this.constructor.getboundPosition(this.word.toLowerCase().toString() , check[i]); + const word_s = this.constructor.getboundPosition(this.text.toLowerCase().toString() , check[i]); before = before_str(0 , word_s).toString().split(" "); - after = after_Str(word_s, this.word).toString().split(" "); + after = after_Str(word_s, this.text).toString().split(" "); //console.log(word.indexOf(word_s)); if (after.length >= 1 ){ @@ -256,7 +256,7 @@ class FilterBadWord{ } catch(err){ - if ( this.word.match(this.filt) != null) { + if ( this.text.match(this.filt) != null) { arry.push("Toxic"); @@ -298,13 +298,13 @@ class FilterBadWord{ var word, process, output, sensore; - word = this.word.split(" "); + word = this.text.split(" "); sensore = "*"; process = position.forEach( number => { - const get_word = this.constructor.getboundPosition(this.word.toString() , number); + const get_word = this.constructor.getboundPosition(this.text.toString() , number); for (var i = 0; i < word.length; i++) { @@ -328,7 +328,7 @@ class FilterBadWord{ //position.forEach( async(number) => { - //const get_word = await this.constructor.getboundPosition(this.word.toString() , number); + //const get_word = await this.constructor.getboundPosition(this.text.toString() , number); //for (var i = 0; i < word.length; i++) { @@ -348,9 +348,9 @@ class FilterBadWord{ class filters_badword extends FilterBadWord{ - ['words_o'](word){ + ['text_o'](text){ - this.word = word.toString(); + this.text = text.toString(); } @@ -387,7 +387,7 @@ class filters_badword extends FilterBadWord{ } else{ - return this.word.trim(); + return this.text.trim(); } From 3704e7c8390bc229936f05b79e43324a1d34e632 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:19:14 +0700 Subject: [PATCH 19/44] badword.js --- badword.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/badword.js b/badword.js index 3e13434..5c4cd3e 100644 --- a/badword.js +++ b/badword.js @@ -39,11 +39,11 @@ class FilterBadWord{ constructor(text = "", customFilter="", customSubFilter=""){ - this.text = text; + this._text = text; - this.filt = /[b8][[a4][s5]hfu[l1][l1]*|k[i1][l1][l1]*|fuck*|dr[uo]g*|d[i1]ck*|fk/gi; + this._filt = /[b8][[a4][s5]hfu[l1][l1]*|k[i1][l1][l1]*|fuck*|dr[uo]g*|d[i1]ck*|fk/gi; - this.subfilter = /ass|lip|pussy*|suck*|mother*|mom*|dog*|low*|sex*/gi; + this._subfilter = /ass|lip|pussy*|suck*|mother*|mom*|dog*|low*|sex*/gi; if (customFilter){ this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); }; @@ -114,7 +114,7 @@ class FilterBadWord{ //if ( typeof position != "number" ) { //position = parseInt(position); //} - this.positionList = this.constructor.position_static(this.text.toString(), this.filt); + this.positionList = this.constructor.position_static(this._text.toString(), this._filt); return this.positionList; @@ -134,7 +134,7 @@ class FilterBadWord{ if (check != null || check != 0) { - var word = this.text.toLowerCase(); + var word = this._text.toLowerCase(); function before_str(number , key){ @@ -149,11 +149,11 @@ class FilterBadWord{ for (var i = 0; i < check.length; i++) { - const word_s = this.constructor.getboundPosition(this.text.toLowerCase().toString() , check[i]); + const word_s = this.constructor.getboundPosition(this._text.toLowerCase().toString() , check[i]); before = before_str(0 , word_s).toString().split(" "); - after = after_Str(word_s, this.text).toString().split(" "); + after = after_Str(word_s, this._text).toString().split(" "); //console.log(word.indexOf(word_s)); if (after.length >= 1 ){ @@ -183,9 +183,9 @@ class FilterBadWord{ try{ - if (before[before.length-1].match(this.subfilter) != null) { + if (before[before.length-1].match(this._subfilter) != null) { - check_repr = before[before.length-1].match(this.subfilter); + check_repr = before[before.length-1].match(this._subfilter); if (check_repr != before[before.length-1]) { //check ulang jika sensore tidak memenuhi persyaratan @@ -206,9 +206,9 @@ class FilterBadWord{ } - else if (after[0].match(this.subfilter) != null){ + else if (after[0].match(this._subfilter) != null){ - check_repr = after[0].match(this.subfilter); + check_repr = after[0].match(this._subfilter); if (check_repr != after[0]) { @@ -229,9 +229,9 @@ class FilterBadWord{ } - else if (after[1].match(this.subfilter) != null){ + else if (after[1].match(this._subfilter) != null){ - check_repr = after[1].match(this.subfilter); + check_repr = after[1].match(this._subfilter); if (check_repr != after[1]) { arry.push("Toxic"); @@ -256,7 +256,7 @@ class FilterBadWord{ } catch(err){ - if ( this.text.match(this.filt) != null) { + if ( this._text.match(this._filt) != null) { arry.push("Toxic"); @@ -298,13 +298,13 @@ class FilterBadWord{ var word, process, output, sensore; - word = this.text.split(" "); + word = this._text.split(" "); sensore = "*"; process = position.forEach( number => { - const get_word = this.constructor.getboundPosition(this.text.toString() , number); + const get_word = this.constructor.getboundPosition(this._text.toString() , number); for (var i = 0; i < word.length; i++) { @@ -328,7 +328,7 @@ class FilterBadWord{ //position.forEach( async(number) => { - //const get_word = await this.constructor.getboundPosition(this.text.toString() , number); + //const get_word = await this.constructor.getboundPosition(this._text.toString() , number); //for (var i = 0; i < word.length; i++) { @@ -350,7 +350,7 @@ class filters_badword extends FilterBadWord{ ['text_o'](text){ - this.text = text.toString(); + this._text = text.toString(); } @@ -387,7 +387,7 @@ class filters_badword extends FilterBadWord{ } else{ - return this.text.trim(); + return this._text.trim(); } From 2726c10528316c578963901dd06af34dd0420575 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:48:29 +0700 Subject: [PATCH 20/44] badword.js --- badword.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/badword.js b/badword.js index 5c4cd3e..d0d470d 100644 --- a/badword.js +++ b/badword.js @@ -44,10 +44,10 @@ class FilterBadWord{ this._filt = /[b8][[a4][s5]hfu[l1][l1]*|k[i1][l1][l1]*|fuck*|dr[uo]g*|d[i1]ck*|fk/gi; this._subfilter = /ass|lip|pussy*|suck*|mother*|mom*|dog*|low*|sex*/gi; - if (customFilter){ + if (customFilter.length>1){ this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); }; - if (customSubFilter){ + if (customSubFilter.length>1){ this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; } @@ -354,11 +354,10 @@ class filters_badword extends FilterBadWord{ } - ['config'](cl=true, smart=true, er=false){ + ['config'](cl=true, smart=true){ this.cl = cl; this.st = smart; - this.er = er; } get ['cleans'](){ From 281088e92ddd97972b215aa4fdc25e99adec29e3 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:49:49 +0700 Subject: [PATCH 21/44] badword.js --- badword.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/badword.js b/badword.js index d0d470d..b0d4b94 100644 --- a/badword.js +++ b/badword.js @@ -354,10 +354,16 @@ class filters_badword extends FilterBadWord{ } - ['config'](cl=true, smart=true){ + ['config'](cl=true, smart=true, customFilter="", customSubFilter=""){ this.cl = cl; this.st = smart; + if (customFilter.length>1){ + this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); + }; + if (customSubFilter.length>1){ + this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); + }; } get ['cleans'](){ From 9efb9b58b1d349563f2f8d0ab3d2d0f97cd0f74a Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:15:32 +0700 Subject: [PATCH 22/44] badword.js --- badword.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/badword.js b/badword.js index b0d4b94..3ed283a 100644 --- a/badword.js +++ b/badword.js @@ -44,10 +44,10 @@ class FilterBadWord{ this._filt = /[b8][[a4][s5]hfu[l1][l1]*|k[i1][l1][l1]*|fuck*|dr[uo]g*|d[i1]ck*|fk/gi; this._subfilter = /ass|lip|pussy*|suck*|mother*|mom*|dog*|low*|sex*/gi; - if (customFilter.length>1){ + if (customFilter.length>3){ this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); }; - if (customSubFilter.length>1){ + if (customSubFilter.length>3){ this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; } @@ -358,10 +358,10 @@ class filters_badword extends FilterBadWord{ this.cl = cl; this.st = smart; - if (customFilter.length>1){ + if (customFilter.length>3){ this._filt = new RegExp(this._filt.source+"|"+escapeRegExp(customFilter), "gi"); }; - if (customSubFilter.length>1){ + if (customSubFilter.length>3){ this._subfilter = new RegExp(this._subfilter.source+"|"+escapeRegExp(customSubFilter), "gi"); }; } From 599707e3a8d9ae649bc73ace1c696bf9f638e8dc Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:22:03 +0700 Subject: [PATCH 23/44] badword.js --- badword.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/badword.js b/badword.js index 3ed283a..1b6dd67 100644 --- a/badword.js +++ b/badword.js @@ -7,7 +7,7 @@ function escapeRegExp(strings){ data[index] = data[index].replace(/[.*+?^${}()|[\]\\]/g, '\\$&'). replace(/[a4]/g, "[a4]").replace(/[s5]/g, "[s5]").replace("i", "[i1]"). replace("l", "[l1]").replace(/[o0]/g, "[o0]").replace(/[e3]/g, "[e3]"). - replace(/[b8]/g, "[b8]"); + replace(/[b8]/g, "[b8]").replace(/[kx]/g, "[kx]"); }; } data = new RegExp(data.join("|")); From 33e2f40461e61d028921de4725eeca5c836d5796 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:33:54 +0700 Subject: [PATCH 24/44] badword.js --- badword.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/badword.js b/badword.js index 1b6dd67..57cef46 100644 --- a/badword.js +++ b/badword.js @@ -425,4 +425,19 @@ const exportsObject = { const isNode = typeof exports === 'object' && typeof module !== 'undefined'; // Ekspor ke lingkungan yang sesuai -isNode ? module.exports = exportsObject : Object.assign(window, exportsObject); +//isNode ? module.exports = exportsObject : Object.assign(window, exportsObject); +// Ekspor ke lingkungan yang sesuai +if (isNode) { + // Jika di Node.js, gunakan module.exports + module.exports = exportsObject; +} else { + // Jika di browser, periksa dukungan ES Modules + if (typeof window.customElements !== "undefined") { + // Dukungan untuk ES Modules, gunakan `export` + window.exportsObject = exportsObject; // Menyimpan di objek window + Object.assign(window, exportsObject); + } else { + // Jika tidak mendukung ES Modules, gunakan Object.assign + Object.assign(window, exportsObject); + } +} From ff66b5c880ab56fbb9901a712fdc5b0155ad0917 Mon Sep 17 00:00:00 2001 From: LcferShell <71859305+LcfherShell@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:02:52 +0700 Subject: [PATCH 25/44] README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 871e2f8..ab72b79 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Tired of offensive language in your app? ๐Ÿšซ **BadFilter.js** to the rescue! We **BadFilter.js** offers two powerful components: - **FilterBadWord Class**: The brains of the operation! This utility class is responsible for filtering unwanted words from your text. -- **filters_badword Class**: A lightweight wrapper around `FilterBadWord` for easier, more streamlined usage. Think of it as the "express mode" for your text-filtering needs! +- **filters_badword Function**: A lightweight wrapper around `FilterBadWord` for easier, more streamlined usage. Think of it as the "express mode" for your text-filtering needs! With these components, you can easily cleanse your text, ensuring a respectful, safe online environment. ๐Ÿš€โœจ @@ -32,9 +32,8 @@ Want to use BadFilter.js in your web app? No problem! Hereโ€™s how: ```html - -