职业
具有完整类型脚本支持的多语言淫秽过滤器
开始
安装软件包
npm i @2toad/profanity
如果使用节点11.x或更高,需要安装 专业 1.x
使用量
import { profanity, CensorType } from '@2toad/profanity';
// or
const { profanity, CensorType } = require('@2toad/profanity');
profanity.exists('I like big butts and I cannot lie');
// true
profanity.exists('I like big glutes and I cannot lie');
// false
profanity.censor('I like big butts (aka arses) and I cannot lie');
// I like big @#$%&! (aka @#$%&!) and I cannot lie
profanity.censor('I like big butts (aka arses) and I cannot lie', CensorType.FirstChar);
// I like big *utts (aka *rses) and I cannot lie
选项
创建纯度类实例来更改默认选项 :
import { Profanity } from '@2toad/profanity';
const profanity = new Profanity({
languages: ['de'],
wholeWord: false,
grawlix: '*****',
grawlixChar: '$',
});
语言
默认设置为 ['en'] (英语). 您可以将默认更改为任意 支持的语言,包括多种语言:
const profanity = new Profanity({
languages: ['en', 'de'],
});
您可以通过指定语言来覆盖此选项 exists 或者说 censor数字 :
profanity.exists('Je suis un connard', ['fr']);
// true
profanity.censor('I like big butts and je suis un connard', CensorType.Word, ['en', 'de', 'fr']);
// I like big @#$%&! and je suis un @#$%&!
如果方法调用中没有指定语言,它将使用选项中指定的语言.
全词
默认设置为 true 所以,污名只匹配整个词:
profanity.exists('Arsenic is poisonous but not profane');
// false
设为 false,导致部分字词匹配:
profanity.exists('Arsenic is poisonous but not profane');
// true (matched on arse)
复合词
迷信检测在复合词的部分上起作用,而不是将连字符或下划线相分离的单词视为不可分割.
何时 wholeWord 实值 true,对复合词的每个部分进行匹配分析:
profanity.exists("Don't be an arsenic-monster");
// false
profanity.exists("Don't be an arse-monster");
// true (matched on arse)
设置 wholeWord 改为 false,导致复合词的每个部分部分字词匹配:
profanity.exists("Don't be an arsenic-monster");
// true (matched on arse)
单码边界
何时 wholeWord 实值 true,这可以控制字词边界是否具有Unicode-aware。 默认设置为 false 由于性能的影响.
- 何时
false(默认),全字匹配使用 ASCII 风格的边界(类似于\b+ 下划线_以为分相. 这对于ASCII输入来说是最快和理想的. - 何时
true,全字比对使用Unicode-aware边界,因此有二甲字(如,vehículo, (中文(简体) ),horário)和复合分离器处理正确.
const profanity = new Profanity({ unicodeWordBoundaries: true });
profanity.exists('vehículo horario');
// false (does not match on "culo" inside "vehículo")
拖动
默认设置为 @#$%&!数字 :
profanity.censor('I like big butts and I cannot lie');
// I like big @#$%&! and I cannot lie
设为 ****,结果为:
profanity.censor('I like big butts and I cannot lie');
// I like big **** and I cannot lie
格劳利克夏
当指定 a CensorType 其他 CensorType.Word,这是该 censor 函数.
默认设置为 *数字 :
profanity.censor('I like big butts and I cannot lie', CensorType.AllVowels);
// I like big b*tts and I cannot lie
设为 $,结果为:
profanity.censor('I like big butts and I cannot lie', CensorType.AllVowels);
// I like big b$tts and I cannot lie
自定义单词列表
添加词:
profanity.addWords(['aardvark', 'zebra']);
删除单词 :
profanity.removeWords(['butt', 'arse']);
白名单
白名单允许您指定被亵渎过滤器总是忽略的单词.
如果您想要启用部分单词匹配, 这将会有所帮助( Name
wholeWord = false),所以组合词被捕获(如arsellicker),而你加入白名单的具体词被忽略了(如砷).
在白名单中添加单词:
profanity.whitelist.addWords(['arsenic', 'buttress']);
删除白名单中的单词 :
profanity.whitelist.removeWords(['arsenic', 'buttress']);
基准制定
看职业表现如何,看看我们 基准结果。 。 。 .
捐款额
所以你想为职业计划捐款? 厉害! 请读一下 贡献 医生开始.