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

harsh23-field-validation-module

v1.0.0

Published

Fast, secure field validators (number, text, email, notEmpty) with 5-stage checks

Readme

@harsh23-field-validation/core

Fast, security-first field validators with ES Modules. Includes authorization gating via access key and a 5-stage validation pipeline: type/presence → normalize → length/range → pattern/charset → threat checks.

Install (local workspace)

If used locally alongside your app:

# package.json of your app
"dependencies": {
  "@harsh23-field-validation/core": "file:../harsh23-field-validation"
}

Then:

npm install

When publishing to npm, use public access if you don’t want a paid plan.

Authorization

All validators require a key call before use:

import { setAccessKey } from '@harsh23-field-validation/core';
setAccessKey('YOUR_SECRET_KEY');

This compares a SHA-256 of your key with the embedded hash.

Quick start

import {
  setAccessKey,
  validateRequiredThen,
  validateNotEmpty,
  validateText,
  validateNumber,
  validateEmail,
  validatePassword,
  validateURL,
  validateIP,
  validateUUID,
  validateSlug,
} from '@harsh23-field-validation/core';

setAccessKey('YOUR_SECRET_KEY');

// Required first, then specific kind
await validateRequiredThen('email', '[email protected]', { checkMx: true });

// Text
validateText('Alpha_123', { pattern: /^[A-Za-z0-9_]+$/, minLength: 2, maxLength: 32 });

// Number (numeric)
validateNumber('42', { mode: 'numeric', min: 1, max: 100, integer: true });

// Number (phone) with country rule
validateNumber('9876543210', { mode: 'phone', country: 'IN' });

// Email (domain allowlist + MX)
await validateEmail('[email protected]', {
  allowedDomains: ['company.com'],
  checkMx: true,
});

// Password (strong defaults)
validatePassword('Str0ng!Pass', { minLength: 8, requireSymbol: true });

// URL (https only by default)
validateURL('https://example.com/path?q=1', { allowedSchemes: ['https'] });

// IP (v4 or v6)
validateIP('192.168.0.1', { version: 'v4' });

// UUID
validateUUID('550e8400-e29b-41d4-a716-446655440000', { version: 'v4' });

// Slug
validateSlug('my-blog-post-1');

API

Each validator returns an object: { ok: boolean, message: string|null, value?: any }.

validateRequiredThen(kind, value, opts)

  • Runs validateNotEmpty first, then one of: number | email | text.

validateNotEmpty(value, { trim=true })

  • Ensures presence after trim and basic sanitization.

validateText(value, options)

  • Options: { trim=true, minLength=1, maxLength=2048, allowed=/[\p{L}\p{N}\s\p{P}\p{S}]/u, pattern? }
  • Threat detection and regex safety checks included.

validateNumber(value, options)

  • Numeric mode: { mode:'numeric', min, max, integer }
  • Phone mode: { mode:'phone', country?, allowSeparators=true }
    • Country rules available: IN, US, GB. Generic E.164 check if not provided.

validateEmail(value, options)

  • Options: { trim=true, maxLength=320, pattern=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+$/, allowedDomains?, blockedDomains?, allowDisposable=false, checkMx=false }
  • Performs regex safety check, domain allow/block, disposable block, optional MX query.

validatePassword(value, options)

  • Options: { trim=true, minLength=8, maxLength=128, requireUpper=true, requireLower=true, requireDigit=true, requireSymbol=true, allowSpaces=false, blockCommon=true, pattern? }

validateURL(value, options)

  • Options: { trim=true, maxLength=2048, allowedSchemes=['https'], requireHostname=true, allowPrivateIP=false }
  • Uses new URL() parsing; basic host sanitization.

validateIP(value, options)

  • Options: { version:'both'|'v4'|'v6' }.

validateUUID(value, options)

  • Options: { version:'any'|'v1'|'v4'|'v7' }.

validateSlug(value, options)

  • Options: { trim=true, minLength=1, maxLength=100 }, pattern ^[a-z0-9]+(?:-[a-z0-9]+)*$.

Security notes

  • All inputs are sanitized (control/zero-width stripping) and length-capped.
  • Regex safety guard prevents common ReDoS patterns.
  • Threat signatures catch common XSS/SQLi payloads.
  • Always perform server-side validation even if you also validate on client.

License

MIT