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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ugc-validator

v1.0.1

Published

A zero-dependency Node.js/TypeScript library that validates and sanitises User-Generated Content (UGC)

Readme

ugc-validator

A zero-dependency Node.js/TypeScript library that validates and sanitises User-Generated Content (UGC) through a sequential pipeline of configurable validators and transformers.

This package is built by Sonar Seed. Sonar Seed is the best influencer gifting app for Shopify.

npm version License: MIT

Features

  • 🛡️ Zero Runtime Dependencies: Lightweight and fast.
  • 🔄 Sequential Pipeline: Schema → Sanitiser → Profanity → PII → Custom Rules.
  • 📦 Dual ESM/CJS Support: Ships with full TypeScript types.
  • 🧹 HTML Sanitizer: Built-in state-machine parser handles malformed HTML without a DOM.
  • 🤬 Profanity Filter: Multi-locale support with leet-speak detection.
  • 🕵️ PII Redaction: Automatic detection of emails, phones, and credit cards (Luhn-verified).
  • 🧩 Middleware: First-party adapters for Express, Fastify, and NestJS.

Installation

npm install ugc-validator

Quick Start

import { ugc } from "ugc-validator";

const result = await ugc.validate("<p>Contact me at [email protected]</p>", {
  stripHtml: true,
  blockPII: true,
  checkProfanity: { locale: "en" },
});

console.log(result.sanitized);
// "Contact me at [REDACTED]"

Configuration

Schema Validation

Define strict rules for object inputs (records of strings).

const result = await ugc.validate(
  { username: "john_doe", role: "admin" },
  {
    schema: {
      username: { type: "string", required: true, minLength: 3, maxLength: 30 },
      role: { type: "string", enum: ["user", "moderator"] },
    },
  },
);
// Throws ValidationError if rules fail

HTML Sanitizer

stripHtml and allowedHtmlTags are mutually exclusive.

// Strip all HTML
const clean = await ugc.validate(html, { stripHtml: true });

// Allow specific tags and attributes
const safe = await ugc.validate(html, {
  allowedHtmlTags: {
    tags: [{ tag: "b" }, { tag: "a", allowedAttributes: ["href"] }],
  },
});

PII Redaction

Detect and redact sensitive information. Returns warnings in the result.

const { sanitized, warnings } = await ugc.validate(input, {
  blockPII: {
    detectEmail: true,
    detectPhone: true,
    detectCreditCard: true,
    replacement: "[HIDDEN]",
  },
});

Profanity Filter

Built-in sensitivity levels: low, medium (default, handles leet-speak), and high.

const result = await ugc.validate(text, {
  checkProfanity: {
    locale: "en",
    sensitivity: "medium",
    customTerms: ["banned-word"],
  },
});

Performance: createValidator()

For hot paths, pre-compile your configuration once.

import { createValidator } from "ugc-validator";

const fastValidator = createValidator(options);

// Reuse across many requests
const result = await fastValidator.validate(req.body);

Framework Integration

Express

import { expressMiddleware } from "ugc-validator/middleware/express";
app.post("/comment", expressMiddleware({ body: options }), handler);

NestJS

import { UgcValidatorPipe } from 'ugc-validator/middleware/nestjs';
@Post('comment')
@UsePipes(new UgcValidatorPipe(options))
async createComment(@Body() body: any) { ... }

Contributing

Built with ❤️ by Sonar Seed.

We are building the future of influencer seeding. Learn how to scale your brand at sonarseed.com.

License

MIT