npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dwcks/bad-word-filter-vi-en

v1.1.3

Published

Thư viện lọc từ xấu tiếng Việt và tiếng Anh

Readme

Bộ Lọc Từ Xấu

Thư viện TypeScript để phát hiện và lọc các từ ngữ xúc phạm trong văn bản, hỗ trợ tiếng Việt và tiếng Anh, bao gồm các từ phân biệt vùng miền. Từ xấu được lưu trong file bad-words.txt hoặc cung cấp trực tiếp qua mảng.

Tính năng

  • Phát hiện từ/cụm từ xúc phạm (không phân biệt hoa/thường).
  • Thay thế từ xấu bằng ký tự che mờ (mặc định: *).
  • Hỗ trợ từ xấu tiếng Việt (ví dụ: địt, đồ Bắc Kỳ) và tiếng Anh (ví dụ: fuck, shit).
  • Tương thích với Node.js, Next.js (server-side), và các môi trường khác.
  • Xử lý lỗi khi đọc file từ xấu.

Cài đặt

npm install @dwcks/bad-word-filter-vi-en

Đảm bảo file bad-words.txt tồn tại trong thư mục gốc của dự án hoặc cung cấp danh sách từ xấu trực tiếp.

Sử dụng

Trong Node.js

import { BadWordFilter } from '@dwcks/bad-word-filter-vi-en';

(async () => {
  const filter = await BadWordFilter.create(); // Đọc từ bad-words.txt
  console.log(filter.hasBadWord('Bình luận có từ địt không?')); // true
  console.log(filter.filter('Bình luận có từ địt không?')); // Bình luận có từ *** không?
})();

Trong Next.js (API Route)

Tạo file pages/api/filter.ts:

import type { NextApiRequest, NextApiResponse } from 'next';
import { BadWordFilter } from '@dwcks/bad-word-filter-vi-en';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  if (req.method === 'POST') {
    try {
      const { text } = req.body;
      if (!text || typeof text !== 'string') {
        return res.status(400).json({ error: 'Văn bản không hợp lệ' });
      }
      const filter = await BadWordFilter.create(['địt', 'ngu']); // Hoặc đọc từ file
      const hasBadWord = filter.hasBadWord(text);
      const filteredText = filter.filter(text);
      res.status(200).json({ hasBadWord, filteredText });
    } catch (error) {
      res.status(500).json({ error: `Lỗi khi lọc: ${error.message}` });
    }
  } else {
    res.status(405).json({ error: 'Phương thức không được hỗ trợ' });
  }
}

Gọi API từ client:

const response = await fetch('/api/filter', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ text: 'Bình luận có từ địt không?' }),
});
const result = await response.json();
console.log(result); // { hasBadWord: true, filteredText: 'Bình luận có từ *** không?' }

Cấu trúc dự án

/bad-word-filter
├── bad-words.txt        # Danh sách từ xấu (UTF-8)
├── dist                 # Code đã biên dịch
├── src
│   ├── BadWordFilter.ts # Lớp lọc chính
│   ├── index.ts         # Xuất module
├── tests
│   ├── test-bad-word-filter.ts # Script kiểm tra
├── README.md
├── LICENSE

Kiểm tra

npm run test

Lưu ý

  • Mã hóa: File bad-words.txt phải được lưu ở định dạng UTF-8.
  • Cụm từ: Regex hiện hỗ trợ cụm từ (ví dụ: đồ Bắc Kỳ). Kiểm tra cẩn thận để tránh khớp sai.
  • Next.js Serverless: Nếu triển khai trên Vercel, đảm bảo cung cấp bad-words.txt trong thư mục gốc hoặc dùng mảng từ xấu.
  • Nhạy cảm văn hóa: Các từ như Bắc Kỳ, Nam Kỳ rất nhạy cảm, sử dụng đúng ngữ cảnh (kiểm duyệt).

Giấy phép

MIT License