# 薄荷过滤装置
**Repository Path**: hive_brown/mint-filter
## Basic Information
- **Project Name**: 薄荷过滤装置
- **Description**: 过滤字符串关键词的库,支持根据词汇列表的过滤,英文名mint-filter。
- **Primary Language**: TypeScript
- **License**: MIT
- **Default Branch**: master
- **Homepage**: https://github.com/ZhelinCheng/mint-filter
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-09-05
- **Last Updated**: 2025-01-31
## Categories & Tags
**Categories**: Uncategorized
**Tags**: String, JavaScript, third
## README
Welcome to mint-filter 👋
> Sensitive word filtering scheme based on the Aho–Corasick algorithm. The Aho–Corasick algorithm is a string search algorithm invented by Alfred V. Aho and Margaret J.Corasick. It is used to match a limited set of "dictionaries" in an input string. " substring in ". It differs from ordinary string matching in that it matches all dictionary strings at the same time. The algorithm has an approximately linear time complexity when amortized, which is approximately the length of the string plus the number of all matches.
## 1. Install
```sh
yarn add mint-filter
```
## 2. Use
### CommonJS Import
```javascript
const { Mint } = require('mint-filter')
```
### TypeScript / ES Module Reference
```typescript
import Mint from 'mint-filter'
const mint = new Mint(['/n', 'text'])
// Basic use
mint.filter(`
Text to be checked.`)
```
## 3. Constructor
• **new Mint**(`Keys to be check.`)
#### Parameters
| Name | Type |
| :------ | :------ |
| `Keys to be check.` | `string`[] |
#### Define on
[index.ts:26](https://github.com/ZhelinCheng/mint-filter/blob/f25e001/src/index.ts#L26)
## 4.Methods (Functions)
### Add key word
▸ **add**(`key`, `build?`): `boolean`
**`Example`**
```typescript
const status = mint.add('Text')
```
#### Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `key` | `string` | `undefined` | Key word |
| `build` | `boolean` | `true` | Whether to build a tree, no need to pass by default |
#### Returns
`boolean` (status)
#### Define on
[index.ts:233](https://github.com/ZhelinCheng/mint-filter/blob/f25e001/src/index.ts#L233)
___
### Delete key word
▸ **delete**(`key`): ``"update"`` \| ``"delete"``
**`Example`**
```typescript
const status = mint.delete('key')
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | Key word |
#### Returns
``"update"`` \| ``"delete"``
Status (update | delete), informs the user whether the node in the tree has been deleted or simply updated.
#### Define on
[index.ts:169](https://github.com/ZhelinCheng/mint-filter/blob/f25e001/src/index.ts#L169)
___
### Filter text
▸ **filter**(`text`, `options?`): `FilterData`
**`Example`**
```typescript
mint.add('unpassable')
let status = mint.filter('An unpassable text.')
console.log(status) // { words: ["unpassable"], text: "An ********** text." }
status = mint.filter('An unpassable text.', { replace: false })
console.log(status) // { words: ["unpassable"], text: "An unpassable text." }
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `text` | `string` | Text content |
| `options?` | `Pick`<`FilterOptions`, ``"replace"``\> | - |
#### Returns
`FilterData`
#### Define on
[index.ts:134](https://github.com/ZhelinCheng/mint-filter/blob/f25e001/src/index.ts#L134)
___
### Check whether the text passes validation
▸ **verify**(`text`): `boolean`
**`Example`**
```typescript
mint.add('unpassable')
const status = mint.verify('An unpassable text.')
console.log(status) // false
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `text` | `string` | Text content |
#### Returns
`boolean`
#### Define on
[index.ts:152](https://github.com/ZhelinCheng/mint-filter/blob/f25e001/src/index.ts#L152)
## 5. Test script
```sh
yarn run test
```