Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

sensitive-word-converter

1.3.3 • Public • Published

Sensitive Word Converter

An asynchronous sensitive word converter/validator based on DFA.

Travis (.com) npm npm

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

  • String validation
  • Random substitute symbol
  • Craw word list with Python
  • Construct the Converter with fileURL
  • Ignore special symbols in strings
  • 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

ISC License

FOSSA Status

Install

npm i sensitive-word-converter

DownloadsWeekly Downloads

1

Version

1.3.3

License

ISC

Unpacked Size

21 kB

Total Files

16

Last publish

Collaborators

  • avatar