1.1.4 • Published 2 years ago

sensitive-word-helper-plus v1.1.4

Weekly downloads
6
License
MIT
Repository
github
Last release
2 years ago

sensitive word helper

📦 安装

npm i -S sensitive-word-helper-plus

yarn add sensitive-word-helper-plus

🎉 使用

NodeJS

const SWH = require('sensitive-word-helper-plus');
const swh = new SWH({
  keywords: ['敏感词数组'],
  step: 3, // 默认是0  // 比如 '敏09感23词sa数45组' 可以替换成 '*09*23*sa*45*'  // step 是从第一个不是节点的字符开始计数
  replacement: '*' // 默认是 *, 比如 'a b' 默认会替换成  '* *'
});

// 异步方法,该方法返回的是一个Promise对象
swh.filter('word').then(res => {});

// 同步方法
swh.filterSync('word');

TypeScript

import SWH from 'sensitive-word-helper-plus';
const swh = new SWH({
  keywords: ['敏感词数组'],
  step: 3, // 默认是0  // 比如 '敏09感23词sa数45组' 可以替换成 '*09*23*sa*45*'  // step 是从第一个不是节点的字符开始计数
  replacement: '*' // 默认是 *, 比如 'a b' 默认会替换成  '* *'
});

// 异步方法,该方法返回的是一个Promise对象
swh.filter('word').then(res => {});

// 同步方法
swh.filterSync('word');

方法

所有方法都提供同步/异步两种。英文字母会全部转换成大写比较。

filter(word, replace)

该方法将返回过滤文本和被过滤的敏感词。

import SWH from 'sensitive-word-helper-plus';
const swh = new SWH({
  keywords: ['敏感词数组'],
  step: 3, // 默认是0  // 比如 '敏09感23词sa数45组' 可以替换成 '*09*23*sa*45*'  // step 是从第一个不是节点的字符开始计数
  replacement: '*' // 默认是 *, 比如 'a b' 默认会替换成  '* *'
});

swh.filter('这是一个敏感词字符串').then(data => {
  console.log(data); // { text: '这是一个***字符串', filter: [ '敏感词' ], pass: false }
});

swh.filter('这是一个敏感词字符串', false).then(data => {
  console.log(data); // { text: '这是一个敏感词字符串', filter: [ '敏感词' ], pass: false }
});

filterSync(word, replace)

  • word<string>:filter 的同步方法。
  • replace<boolean>:是否需要替换敏感词(替换成*,默认开启)。
  • returns: <FilterValue>

every(word)

判断文本是否通过敏感词验证,发现敏感词立即返回false,为true表示通过验证,没有敏感词。该方法是一个异步方法,将会返回一个 Promise 对象。

import SWH from 'sensitive-word-helper-plus';
const swh = new SWH({
  keywords: ['敏感词数组'],
  step: 3, // 默认是0  // 比如 '敏09感23词sa数45组' 可以替换成 '*09*23*sa*45*'  // step 是从第一个不是节点的字符开始计数
  replacement: '*' // 默认是 *, 比如 'a b' 默认会替换成  '* *'
});

swh.every('这是一个敏感词字符串').then(data => {
  console.log(data); // true
});

everySync(word)

  • word<string>:需要验证的字符串文本。
  • returns: <boolean>
1.1.4

2 years ago

1.1.3

2 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago