@jayfong/x-server 2.2.15 → 2.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,6 +7,8 @@ exports.SensitiveWordsService = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _mintFilter = _interopRequireDefault(require("mint-filter"));
|
|
9
9
|
|
|
10
|
+
var _vtils = require("vtils");
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* 敏感词服务。
|
|
12
14
|
*/
|
|
@@ -16,6 +18,20 @@ class SensitiveWordsService {
|
|
|
16
18
|
this.serviceName = 'sensitiveWords';
|
|
17
19
|
this.mint = void 0;
|
|
18
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* 文本转换。
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
transform(text) {
|
|
27
|
+
return (// 移除空白字符
|
|
28
|
+
(0, _vtils.removeBlankChars)( // 移除非单词字符
|
|
29
|
+
(0, _vtils.removeNonWordChars)( // 全角转半角
|
|
30
|
+
(0, _vtils.toHalfWidthString)(text))) // 转小写
|
|
31
|
+
.toLowerCase() // 叠词归一
|
|
32
|
+
.replace(/(.)\1+/g, '$1')
|
|
33
|
+
);
|
|
34
|
+
}
|
|
19
35
|
/**
|
|
20
36
|
* 处理文本,敏感词将被替换为 * 号。
|
|
21
37
|
*/
|
|
@@ -26,7 +42,7 @@ class SensitiveWordsService {
|
|
|
26
42
|
this.mint = new _mintFilter.default(this.options.words);
|
|
27
43
|
}
|
|
28
44
|
|
|
29
|
-
const res = await this.mint.filter(text, {
|
|
45
|
+
const res = await this.mint.filter(this.transform(text), {
|
|
30
46
|
every: true,
|
|
31
47
|
replace: true,
|
|
32
48
|
words: false
|
|
@@ -43,7 +59,7 @@ class SensitiveWordsService {
|
|
|
43
59
|
this.mint = new _mintFilter.default(this.options.words);
|
|
44
60
|
}
|
|
45
61
|
|
|
46
|
-
const res = await this.mint.filter(text, {
|
|
62
|
+
const res = await this.mint.filter(this.transform(text), {
|
|
47
63
|
replace: false,
|
|
48
64
|
every: !!every,
|
|
49
65
|
words: true
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Mint from 'mint-filter';
|
|
2
|
+
import { removeBlankChars, removeNonWordChars, toHalfWidthString } from 'vtils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 敏感词服务。
|
|
@@ -9,6 +10,20 @@ export class SensitiveWordsService {
|
|
|
9
10
|
this.serviceName = 'sensitiveWords';
|
|
10
11
|
this.mint = void 0;
|
|
11
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* 文本转换。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
transform(text) {
|
|
19
|
+
return (// 移除空白字符
|
|
20
|
+
removeBlankChars( // 移除非单词字符
|
|
21
|
+
removeNonWordChars( // 全角转半角
|
|
22
|
+
toHalfWidthString(text))) // 转小写
|
|
23
|
+
.toLowerCase() // 叠词归一
|
|
24
|
+
.replace(/(.)\1+/g, '$1')
|
|
25
|
+
);
|
|
26
|
+
}
|
|
12
27
|
/**
|
|
13
28
|
* 处理文本,敏感词将被替换为 * 号。
|
|
14
29
|
*/
|
|
@@ -19,7 +34,7 @@ export class SensitiveWordsService {
|
|
|
19
34
|
this.mint = new Mint(this.options.words);
|
|
20
35
|
}
|
|
21
36
|
|
|
22
|
-
const res = await this.mint.filter(text, {
|
|
37
|
+
const res = await this.mint.filter(this.transform(text), {
|
|
23
38
|
every: true,
|
|
24
39
|
replace: true,
|
|
25
40
|
words: false
|
|
@@ -36,7 +51,7 @@ export class SensitiveWordsService {
|
|
|
36
51
|
this.mint = new Mint(this.options.words);
|
|
37
52
|
}
|
|
38
53
|
|
|
39
|
-
const res = await this.mint.filter(text, {
|
|
54
|
+
const res = await this.mint.filter(this.transform(text), {
|
|
40
55
|
replace: false,
|
|
41
56
|
every: !!every,
|
|
42
57
|
words: true
|