@jayfong/x-server 2.30.1 → 2.30.2
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.
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.SensitiveWordsService = void 0;
|
|
5
5
|
var _vtils = require("vtils");
|
|
6
|
+
var _regexp = require("vtils/regexp");
|
|
7
|
+
const phoneNumberRegExp = _regexp.phoneNumberRegExpBuilder.build();
|
|
8
|
+
const toRegExp = (0, _vtils.memoize)(re => new RegExp(re.substring(1, re.length - 1)), re => re);
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* 敏感词服务。
|
|
8
12
|
*/
|
|
@@ -28,7 +32,8 @@ class SensitiveWordsService {
|
|
|
28
32
|
// 转小写
|
|
29
33
|
.toLowerCase()
|
|
30
34
|
// 叠词归一
|
|
31
|
-
|
|
35
|
+
// 排除字母数字以支持qq、手机号等场景
|
|
36
|
+
.replace(/([^a-zA-Z0-9])\1+/g, '$1')
|
|
32
37
|
);
|
|
33
38
|
}
|
|
34
39
|
|
|
@@ -39,7 +44,11 @@ class SensitiveWordsService {
|
|
|
39
44
|
text = this.transform(text);
|
|
40
45
|
const words = [];
|
|
41
46
|
for (const word of this.sensitiveWords) {
|
|
42
|
-
if (
|
|
47
|
+
if (
|
|
48
|
+
// 支持 <手机号>
|
|
49
|
+
word === '<手机号>' ? phoneNumberRegExp.test(text) :
|
|
50
|
+
// 支持正则
|
|
51
|
+
word[0] === '/' && word[word.length - 1] === '/' ? toRegExp(word).test(text) : text.includes(word)) {
|
|
43
52
|
words.push(word);
|
|
44
53
|
if (!every) break;
|
|
45
54
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { removeBlankChars, removeNonWordChars, toHalfWidthString, uniq } from 'vtils';
|
|
1
|
+
import { memoize, removeBlankChars, removeNonWordChars, toHalfWidthString, uniq } from 'vtils';
|
|
2
|
+
import { phoneNumberRegExpBuilder } from 'vtils/regexp';
|
|
3
|
+
const phoneNumberRegExp = phoneNumberRegExpBuilder.build();
|
|
4
|
+
const toRegExp = memoize(re => new RegExp(re.substring(1, re.length - 1)), re => re);
|
|
5
|
+
|
|
2
6
|
/**
|
|
3
7
|
* 敏感词服务。
|
|
4
8
|
*/
|
|
@@ -24,7 +28,8 @@ export class SensitiveWordsService {
|
|
|
24
28
|
// 转小写
|
|
25
29
|
.toLowerCase()
|
|
26
30
|
// 叠词归一
|
|
27
|
-
|
|
31
|
+
// 排除字母数字以支持qq、手机号等场景
|
|
32
|
+
.replace(/([^a-zA-Z0-9])\1+/g, '$1')
|
|
28
33
|
);
|
|
29
34
|
}
|
|
30
35
|
|
|
@@ -35,7 +40,11 @@ export class SensitiveWordsService {
|
|
|
35
40
|
text = this.transform(text);
|
|
36
41
|
const words = [];
|
|
37
42
|
for (const word of this.sensitiveWords) {
|
|
38
|
-
if (
|
|
43
|
+
if (
|
|
44
|
+
// 支持 <手机号>
|
|
45
|
+
word === '<手机号>' ? phoneNumberRegExp.test(text) :
|
|
46
|
+
// 支持正则
|
|
47
|
+
word[0] === '/' && word[word.length - 1] === '/' ? toRegExp(word).test(text) : text.includes(word)) {
|
|
39
48
|
words.push(word);
|
|
40
49
|
if (!every) break;
|
|
41
50
|
}
|