Skip to content

أمثلة عملية

اربط المكتبة في تطبيقك ثم اختبر من التجربة المباشرة أو npx anti-ttyah.

نموذج في المتصفح

ts
import { contains, mask } from "anti-ttyah";

const form = document.querySelector("form")!;
const comment = document.querySelector<HTMLTextAreaElement>("#comment")!;

form.addEventListener("submit", (event) => {
  if (contains(comment.value)) {
    event.preventDefault();
    comment.value = mask(comment.value);
    comment.setCustomValidity("Please remove blocked language.");
    comment.reportValidity();
  }
});

حقول الخادم

ts
import { blockedError } from "anti-ttyah";

export function moderate(title: string, body: string) {
  const err = blockedError({ title, body });
  if (err) return { status: 400, ...err };
  return { status: 200 };
}

قائمة لمشروع واحد

ts
import { createFilter } from "anti-ttyah";

const comments = createFilter({
  extraTerms: ["competitor-slur"],
  allowlist: ["h*ar"],
  categories: ["sexual", "slur", "insult"],
  maskStyle: "token",
});

الفحص في CI

bash
npx anti-ttyah --file comments.txt
# 0 نظيف، 1 محظور

GitHub Actions

yaml
name: Moderate comments file
on: [push]
jobs:
  filter:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npx anti-ttyah --file comments.txt

لماذا ليس bad-words؟

فلتر إنجليزي شائعانتي تطياح
الإنجليزيةنعمنعم
الفرنسيةأحياناًنعم
العربية (رسم + دردشة لاتينية)لانعم
أرقام الفرانكو-عرب (3/7/9)لانعم
الأمازيغيةلاقائمة محافظة
يعمل دون اتصالنعمنعم

رخصة MIT · يعمل محلياً في Node والمتصفح · بلا اعتماديات