pottymouth-client
Version:
dictionary and slug matching lookups for verbal blunders
2 lines • 1.98 kB
JavaScript
!function(a,b){"function"==typeof define&&define.amd?define(["pottymouth","json!badwords"],function(c,d){return a.pottymouth=b(c,d)}):"object"==typeof exports?module.exports=b(require("pottymouth"),require("badwords")):a.pottymouth=b(a.pottymouth,null)}(this,function(a,b){var c=this||global,a={threshold:.5},d={},e=["\\b(as{2,})","(p([o|0]{1,})rn)","(pus{2,})","(sh([i|\\W|\\d]+)[t|+])","((f|ph)([u|c|k|q]+)([u|c|k|q]+))","(d([i|1]+)ldo)","(f([a|\\@]+)g)","(bu([t|\\W]+))","(b([i|\\W])a?tch)","(b([o|0]{2,})bs?)","((c[o|0]ck)([\\w|\\W]?)+)","(cl[i|1]+t)","(c(o{2,})n)","(blow|cu[m|nt]+)","(d([i|\\d|\\W]+)ck)","(f[a|\\W]([n]+)y)","(f([a|\\W]+t((a|\\W|\\d])[s|\\W|\\d]?|[f|ph].+)?))","(n([i|1]+)gg)","(p([e|3]+)n([i|1]{1,})s)","(pis{2,})","(t([i|\\W|\\d]+)(t+).+)","(tw([a|\\W|\\d]t+))","(b([o|0]+)n([e|\\d|\\W]+r))","(wh([o|\\d|\\W]+)r([e|\\d|\\W]+))"];return d.dictionary=function(b){return!!a.badwords.context[b]},d.regex=function(b){for(var c=0,d=Math.floor(b.length*a.threshold),f=e.length-1;f>=0;f--){var g=new RegExp(e[f],"gi"),b=b.replace(/[\s|\_]/g,""),h=b.match(g);if(h&&(c+=h[0].length,c>d))break}return c>d},a.badwords={context:b,ignore:!1,set:function(a){if(a instanceof Object)return void(this.context=a);var b=this,c=new XMLHttpRequest,d=function(){b.context=JSON.parse(this.responseText)};c.onload=d,c.open("get",a,!0),c.send()}},a.validate={threshold:{get:function(){return a.threshold},set:function(b){if(isNaN(parseInt(b,10)))throw new Error("Can't set threshold to a non-number.");a.threshold=1>b?b:1}},full:function(a){return this.preflight(a),this.dictionary(a)?!0:this.regex(a)},dictionary:function(a){return this.preflight(a),d.dictionary.call(c,a)},preflight:function(b){if(!b)throw new Error("validate requires a word to filter.");if(!a.badwords.ignore&&!a.badwords.context)throw new Error("badwords is required. set badwords before validation.")},regex:function(a){return this.preflight(a),d.regex.call(c,a)}},a});
//# sourceMappingURL=/pottymouth.map