🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

fastscan

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastscan

quickly search by ahocorasick algorithm

Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
477
-69.46%
Maintainers
1
Weekly downloads
 
Created
Source

FastScan

苦于没有找到一个比较合适的敏感词过滤库,所以我自己花了点时间撸了一个。 它基于广为人知的 ahocorasick 字符串匹配算法,使用原生的 js 实现。

安装方法

# 安装到当前项目
npm install --save fastscan
# 运行单元测试
npm test

使用方法

import FastScanner from fastscan

var words = ["今日头条","微信", "支付宝"]
var scanner = new FastScanner(words)
var content = "今日头条小程序终于来了,这是继微信、支付宝、百度后,第四个推出小程序功能的App。猫眼电影率先试水,出现在今日头条。"
var offWords = scanner.search(content)
console.log(offWords)
var hits = scanner.hits(content)
console.log(hits)

-------------
[ [ 0, '今日头条' ], [ 15, '微信' ], [ 18, '支付宝' ], [ 53, '今日头条' ] ]
{ '今日头条': 2, '微信': 1, '支付宝': 1 }

API

  • 查询匹配的词汇以及所在字符串的位置 search(content, option={})
  • 查询匹配词汇的命中数量 hits(content, options={})
  • 临时动态增加词汇,不修正其它词汇的回溯指针 add(word)
options = {quick: false, longest: false}
  • quick 选项表示快速模式,匹配到一个就立即返回
  • longest 表示最长模式,同一个位置出现多个词汇(中国、中国人),选择最长的一个(中国人)
  • 默认匹配出所有的词汇,同一个位置可能会出现多个词汇

Keywords

ahocorasick

FAQs

Package last updated on 23 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts