
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
sensitive-word-filtering
Advanced tools
A Node.js library for filtering sensitive words using a prefix tree (Trie).
基于 Node.js 实现的敏感词过滤脚本,使用前缀树(Trie)结构,支持高效匹配、大小写忽略、空格忽略功能。
使用 NPM 安装:
npm install sensitive-word-filtering
const Trie = require('sensitive-word-filtering');
const trie = new Trie();
// 添加敏感词
trie.insert('敏感词1');
trie.insert('敏感词12');
// 过滤文本
const inputText = '敏 感 词1 和其他内容。';
const filteredText = trie.filter({
text: inputText,
ignoreCase: true, // 忽略大小写
ignoreSpaces: true, // 忽略空格
});
console.log(filteredText); // 输出: **** 和其他内容
import Trie from 'sensitive-word-filtering';
const trie = new Trie();
// 插入敏感词
trie.insert('SensitiveWord');
trie.insert('BadWord');
// 测试文本
const text = 'This text contains SensitiveWord and other stuff.';
const result = trie.filter({ text, ignoreCase: true });
console.log(result); // 输出: This text contains ************ and other stuff.
insert(word: string): void
contains(word: string): boolean
delete(word: string): void
filter(options: { text: string; ignoreCase?: boolean; ignoreSpaces?: boolean }): string
功能: 过滤文本中的敏感词。
参数:
text: 要过滤的文本。
ignoreCase: 是否忽略大小写(默认为 false)。
ignoreSpaces: 是否忽略空格(默认为 false)。
返回值: 过滤后的文本。
A sensitive word filtering script implemented in Node.js, using a prefix tree (Trie) structure. Supports efficient matching, case-insensitivity, and space-insensitivity.
🌟 Efficient sensitive word filtering (Trie-based). 🌟 Supports case-insensitive matching. 🌟 Supports ignoring spaces during filtering. 🌟 Dynamically add and remove sensitive words.
Install via NPM:
npm install sensitive-word-filtering
const Trie = require('sensitive-word-filtering');
const trie = new Trie();
// Add sensitive words
trie.insert('SensitiveWord1');
trie.insert('SensitiveWord12');
// Filter text
const inputText = 'This contains SensitiveWord1 and some other text.';
const filteredText = trie.filter({
text: inputText,
ignoreCase: true, // Ignore case
ignoreSpaces: true, // Ignore spaces
});
console.log(filteredText); // Output: This contains **** and some other text.
import Trie from 'sensitive-word-filtering';
const trie = new Trie();
// Insert sensitive words
trie.insert('SensitiveWord');
trie.insert('BadWord');
// Test text
const text = 'This text contains SensitiveWord and other stuff.';
const result = trie.filter({ text, ignoreCase: true });
console.log(result); // Output: This text contains ************ and other stuff.
insert(word: string): void
contains(word: string): boolean
delete(word: string): void
filter(options: { text: string; ignoreCase?: boolean; ignoreSpaces?: boolean }): string
Function: Filter sensitive words in the text.
Parameters:
text: The text to filter.
ignoreCase: Whether to ignore case (default false).
ignoreSpaces: Whether to ignore spaces (default false).
Returns: The filtered text.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A Node.js library for filtering sensitive words using a prefix tree (Trie).
The npm package sensitive-word-filtering receives a total of 36 weekly downloads. As such, sensitive-word-filtering popularity was classified as not popular.
We found that sensitive-word-filtering demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.