sensitive-word-converter
v1.3.3
Published
An asynchronous sensitive word converter/validator based on DFA.
Downloads
14
Maintainers
Readme
Sensitive Word Converter
An asynchronous sensitive word converter/validator based on DFA.
Getting Started
$ npm i sensitive-word-converter
Usage
import { Converter } from 'sensitive-word-converter';
// At least one text file containing sensitive words is required
const converter = new Converter( // Local file paths or URLs
'./sensitiveWords.txt',
'https://raw.githubusercontent.com/observerss/textfilter/master/keywords',
// ...
);
converter.isReady.then(() => {
// Sensitive word: He, World
let s0 = converter.convert('Hello World');
console.log(s0); // **llo *****
// Sensitive word: 你好骚啊
let s1 = converter.convert('你好骚啊!');
console.log(s1); // ****!
// Sensitive word: 哈
let s2 = converter.convert('哈哈哈哈啪!', '喵');
console.log(s2); // 喵喵喵喵啪!
// String validation
let r0 = converter.validate('Hello World');
console.log(r0); // { pass: false, sensitiveWords: Set { 'He', 'World' } }
}).catch(e => {
console.error(e);
// Handle error
})
Sensitive Words Example
Todo List
- [X] String validation
- [ ] Random substitute symbol
- [ ] Craw word list with Python
- [X] Construct the Converter with fileURL
- [ ] Ignore special symbols in strings
- [X] Add support for multi-file word lists
- [ ] Set timeout for each request
For Developers/Testers
$ git clone --depth=1 https://github.com/m8524769/sensitive-word-converter.git
$ cd ./sensitive-word-converter
$ npm i --only=dev
$ npm run build
$ npm test