Recipes
Guides stay starred. Wire these into your app, then verify with the playground or npx anti-ttyah.
Browser form
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();
}
});Node / Express-style fields
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 };
}blockedError also accepts loose string arguments or string arrays.
Custom list for one product
ts
import { createFilter } from "anti-ttyah";
const comments = createFilter({
extraTerms: ["competitor-slur"],
allowlist: ["h*ar"],
categories: ["sexual", "slur", "insult"],
maskStyle: "token",
});CLI in CI
bash
npx anti-ttyah --file comments.txt
# exit 0 clean, 1 blockedJSON for logs:
bash
npx anti-ttyah --json --file comments.txt
npx anti-ttyah --explain --file comments.txtGitHub 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.txtWhy not bad-words?
| typical EN filter | Anti-Ttyah | |
|---|---|---|
| English | yes | yes |
| French | sometimes | yes |
| Arabic (script + Latin chat) | no | yes |
Franco-arabe digits (3/7/9) | no | yes |
| Tamazight | no | conservative list |
| Runs offline | yes | yes |