Lightweight TypeScript anti-spam guard primitives for content moderation, chat moderation, UGC moderation, rate limiting, duplicate detection, burst detection, and actor-based message checks.
Use @textfilters/spam to add stateful spam checks beside censoring and
redaction filters in a composable TypeScript text filtering library.
Add the GitHub Packages registry for the @textfilters scope:
@textfilters:registry=https://npm.pkg.github.comInstall with GitHub npm authentication configured. GitHub Packages requires authentication for npm installs, including public packages.
npm install @textfilters/core @textfilters/spam- Block repeated, too-fast, or bursty messages in chat moderation workflows.
- Add actor-based anti-spam checks before running heavier content moderation.
- Return stable spam decision reasons for application-specific moderation policy.
- Keep rate limiting and duplicate detection separate from text censoring filters.
import { createSpamFilter } from "@textfilters/spam";
const spam = createSpamFilter({
minIntervalMs: 700,
duplicateWindowMs: 12_000,
burstWindowMs: 10_000,
burstMaxMessages: 6,
});
const decision = spam.check({
actorKey: "user:123",
text: "hello",
});createSpamFilter(config?) returns a stateful guard with stable name: "spam" and a reset() method. The spamFilter(config?) export is a backwards-compatible alias for createSpamFilter(config?).
The package provides an in-memory, actor-based spam guard for interval, duplicate, and burst checks. Each blocked decision returns a stable reason so callers can apply their own moderation policy.
Actor state is bounded by pruning stale entries as messages are checked. Use one guard instance for a shared moderation scope, or create isolated instances for separate tenants or test cases.
See docs/architecture.md for the decision flow, module map, and change guide.
@textfilters/corefor shared pipeline, normalization, and range masking primitives.@textfilters/urlfor URL detection, obfuscated links, and safe link censoring.@textfilters/emailfor email detection and contact redaction.@textfilters/phonefor phone number detection and contact redaction.@textfilters/profanityfor Russian profanity filtering and taxonomy-backed moderation.
Releases are managed by Release Please from Conventional Commit history on main. When a Release Please release is created, the workflow runs npm run check and publishes the package to GitHub Packages. Release tags keep the v* pattern.
The package is prepared for publication to GitHub Packages, not the public npm registry.
MIT