@2toad/profanity 中文文档教程

发布于 4年前 浏览 36 项目主页 更新于 3年前

Profanity

GitHub 版本 下载Build status

一个 JavaScript 亵渎过滤器(支持 TypeScript)

Getting Started

安装包

npm i @2toad/profanity

Usage

import { profanity } from '@2toad/profanity';
// or
var profanity = require('@2toad/profanity').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

Options

创建一个亵渎类的实例来更改默认选项:

import { Profanity, ProfanityOptions } from '@2toad/profanity';

const options = new ProfanityOptions();
options.wholeWord = false;
options.grawlix = '*****';

const profanity = new Profanity(options);

wholeWord

默认设置为 true,所以脏话只匹配整个单词:

profanity.exists('Arsenic is poisonous but not profane');
// false

将此设置为 false,导致部分单词匹配:

profanity.exists('Arsenic is poisonous but not profane');
// true (matched on arse)

grawlix

默认设置为 @#$%&!

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

Customize the word list

添加单词:

profanity.addWords(['aardvark', 'zebra']);

删除单词:

profanity.removeWords(['butt', 'arse']);

Whitelist

白名单允许您指定脏话过滤器始终忽略的单词。

如果您想打开部分单词匹配 (wholeWord = true),这会很有用,这样组合的单词会被捕获(例如,arseliccker),而您添加到白名单的特定单词会被忽略(例如,砷)。

添加单词到白名单:

profanity.whitelist.addWords(['arsenic', 'buttress']);

从白名单中删除单词:

profanity.whitelist.removeWords(['arsenic', 'buttress']);

Profanity

GitHub versionDownloadsBuild status

A JavaScript profanity filter (with TypeScript support)

Getting Started

Install package

npm i @2toad/profanity

Usage

import { profanity } from '@2toad/profanity';
// or
var profanity = require('@2toad/profanity').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

Options

Create an instance of the Profanity class to change the default options:

import { Profanity, ProfanityOptions } from '@2toad/profanity';

const options = new ProfanityOptions();
options.wholeWord = false;
options.grawlix = '*****';

const profanity = new Profanity(options);

wholeWord

By default this is set to true, so profanity only matches on whole words:

profanity.exists('Arsenic is poisonous but not profane');
// false

Setting this to false, results in partial word matches:

profanity.exists('Arsenic is poisonous but not profane');
// true (matched on arse)

grawlix

By default this is set to @#$%&!:

profanity.censor('I like big butts and I cannot lie');
// I like big @#$%&! and I cannot lie

Setting this to ****, results in:

profanity.censor('I like big butts and I cannot lie');
// I like big **** and I cannot lie

Customize the word list

Add words:

profanity.addWords(['aardvark', 'zebra']);

Remove words:

profanity.removeWords(['butt', 'arse']);

Whitelist

The whitelist allows you to specify words that are always ignored by the profanity filter.

This can be useful if you want to turn partial word matching on (wholeWord = true), so combined words are caught (e.g., arselicker), while specific words you add to the whitelist are ignored (e.g., arsenic).

Add words to the whitelist:

profanity.whitelist.addWords(['arsenic', 'buttress']);

Remove words from the whitelist:

profanity.whitelist.removeWords(['arsenic', 'buttress']);
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文