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

@formpipe/validators

v0.1.5

Published

A collection of validators and sanitizers for form inputs in TypeScript.

Readme

@formpipe/validators

A collection of validation tools for forms

  • Email validation
  • Types check
  • min and max contraints

See npm package for references

Installation

npm install @formpipe/validators

Usage

isEmail(value: unknown): boolean

Validates if a value is a properly formatted email address.

import { isEmail } from '@formpipe/validators';

isEmail('[email protected]'); // true
isEmail('invalid-email'); // false

isString(value: unknown): value is string

Type guard that checks if a value is a string.

import { isString } from '@formpipe/validators';

isString('hello'); // true
isString(123); // false
isString(null); // false

isInRange(value: string, min: number, max: number): boolean

Checks if a string's length is within a specified range (inclusive).

import { isInRange } from '@formpipe/validators';

isInRange('hello', 3, 6); // true (5 characters, between 3 and 6)
isInRange('hi', 3, 6); // false (2 characters, less than min)
isInRange('greetings', 3, 6); // false (9 characters, more than max)
isInRange('', 0, 5); // true (empty string allowed when min is 0)
isInRange('👋🌍', 2, 5); // true (2 characters)

Handles:

  • Empty strings (valid when min=0)
  • Unicode characters and emojis
  • Special characters
  • Input validation (returns false for non-string inputs)

sanitize(value: string): string

Sanitizes HTML input by removing all HTML tags, scripts, and potentially dangerous attributes.
Returns the clean text, trimmed of whitespace at the start and end.

import { sanitize } from '@formpipe/validators';

// Clean input
sanitize('<p>Hello World</p>');
// "Hello World"

// Malicious input
sanitize('<script>alert("XSS")</script>Hello');
// "Hello"

// With event handlers
sanitize('<div onclick="evil()">Click me </div>');
// "Click me"

Detects and removes:

- Script tags
- Inline event handlers
- Dangerous URLs (javascript:, data:, vbscript:)
- HTML tags while preserving content
- Decodes HTML entities

### escapeHtml(value: string): string

Escapes HTML special characters in a string to prevent XSS. Useful when you need to display user input as HTML.

```typescript
import { escapeHtml } from '@formpipe/validators';

escapeHtml('<p>Hello & World</p>');
// "&lt;p&gt;Hello &amp; World&lt;/p&gt;"

escapeHtml('Quote "test" & <tags>');
// "Quote &quot;test&quot; &amp; &lt;tags&gt;"

isPhone(value: string, mode?: 'loose' | 'strict' | 'e164'): boolean

Validates whether a string is a valid phone number according to the selected validation mode.

Supported modes:

  • 'e164' (default): Follows the international E.164 standard — optional +, 8–15 digits, cannot start with 0.

  • 'strict': Digits only (0–9), minimum 8 and maximum 15 characters.

  • 'loose': Allows spaces, +, parentheses, and hyphens — requires at least 8 digits.

import { isPhone } from '@formpipe/validators';

// E.164 format (default)
isPhone('+14155552671'); // true
isPhone('0000000'); // false

// Strict mode: digits only
isPhone('1234567890', 'strict'); // true
isPhone('+1234567890', 'strict'); // false

// Loose mode: allows spaces, parentheses, and hyphens
isPhone('(123) 456-7890', 'loose'); // true
isPhone('+34 600 123 456', 'loose'); // true

Contributing

Contributions are currently closed while the monorepo structure and core architecture are being developed. You’re welcome to open issues or leave suggestions anyway!

License

MIT License