You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
700 B
33 lines
700 B
import _ from 'lodash'
|
|
|
|
/**
|
|
* 敏感词替换为*
|
|
* @param reg 敏感词数组
|
|
* @param str 校验文本
|
|
*/
|
|
function replaceTaboo(reg, str) {
|
|
// 深拷贝文字,逐步替换每个敏感词
|
|
let val = _.cloneDeep(str)
|
|
for (let i = 0; i < reg.length; i++) {
|
|
val = val.replace(new RegExp(reg[i], 'g'), function ($0) {
|
|
return '***'
|
|
})
|
|
}
|
|
return val
|
|
}
|
|
|
|
/**
|
|
* 校验是否包含链接
|
|
* @param str 校验文本
|
|
*/
|
|
function isContainsLink(str) {
|
|
if (!str) return false
|
|
// 匹配 http://, https:// 或 www. 开头的链接
|
|
const reg = /(http:\/\/|https:\/\/|www\.)[a-zA-Z0-9\.\/\\?%=&-_]+/gi
|
|
return reg.test(str)
|
|
}
|
|
|
|
export default {
|
|
replaceTaboo,
|
|
isContainsLink,
|
|
}
|
|
|