Skip to content

stultuss/sensitive-words-filter

Repository files navigation

sensitive-words-filter

NPM Version NPM Downloads Build Linux Build Windows Build Test Coverage

文字过滤,支持敏感词匹配,由DFA算法实现

ChangeLog

20250110

  1. 优化代码结构。
  2. 增加识别敏感词中间填充了特殊字符的情况。
  3. replace 接口增加自定义特殊字符过滤字段。

Install

npm install sensitive-words-dfa-filter --save

How to use

let Filter = require('sensitive-words-dfa-filter');

// 设定需要搜索的敏感字
let search = [
  'f',
  'filter'
];

// 初始化文字过滤器,将敏感字做成字典
Filter.instance().init(search);

// 运行
console.log(Filter.instance().replace('This is "fuck" filter word!')); // This is "****" filter word!
console.log(Filter.instance().replace('This is "f u c k" filter word!')); // This is "*******" filter word!
console.log(Filter.instance().replace('This is "f@u@c@k" filter word!')); // This is "*******" filter word!
console.log(Filter.instance().replace('This is "fAuBcCk" filter word!', '?', 'ABC')); // This is "???????" filter word!

About

文字过滤,支持敏感词匹配,由DFA算法实现

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published