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

@ferrow/input-validator

v2.0.0

Published

Rule-string validation engine ("required|number|min:18"), nested object schemas, array item validation, custom rules, and full error collection with field paths. Zero runtime dependencies.

Readme

input-validator

CI

A rule-string validation engine for TypeScript/Node — Laravel-style rule strings ("required|number|min:18|max:120"), nested object schemas, array item validation, custom rule registration, and full error collection (not just the first failure) with dot/bracket field paths. Zero runtime dependencies.

Install

Copy src/index.ts into your project, or build this repo (npm run build) and depend on the compiled dist/.

Quickstart

import { validate } from 'input-validator';

const schema = {
  name: 'required|string|length:2,50',
  email: 'required|email',
  age: 'number|min:18|max:120',
};

const { valid, errors } = validate(schema, { name: 'A', email: 'bad', age: 15 });
// valid: false
// errors: [
//   { path: 'name', message: 'name must have length >= 2' },
//   { path: 'email', message: 'email must be a valid email' },
//   { path: 'age', message: 'age must be >= 18' },
// ]

Or use the class form to reuse one schema:

import { InputValidator } from 'input-validator';
const validator = new InputValidator(schema);
validator.validate(payload);

Built-in rules

required · string · number · boolean · email · min:N (numeric >= N, or string length >= N) · max:N (numeric <= N, or string length <= N) · length:min,max (string length range) · in:a,b,c (must equal one of the comma-separated values) · regex:pattern (tested with new RegExp(pattern))

A field without required is skipped entirely (no errors) when its value is undefined, null, or ''.

Nested schemas and arrays

const schema = {
  address: { schema: { city: 'required|string', zip: 'regex:^[0-9]{5}$' } },
  tags: { array: 'string' },                              // array of primitives
  friends: { arraySchema: { name: 'required|string' } },  // array of objects
};

Error paths reflect nesting: address.city, friends[0].name.

Custom rules

import { registerRule } from 'input-validator';

registerRule('even', (value) => (typeof value === 'number' && value % 2 === 0 ? null : 'must be even'));
validate({ n: 'number|even' }, { n: 3 }); // { valid: false, errors: [{ path: 'n', message: 'n must be even' }] }

registerRule is global — it adds the rule name for every schema in the process, matching how the built-in rules are registered.

Scope and limits

  • Rule arguments are always plain strings (min:18, in:a,b,c) — no cross-field rules (e.g. "must equal another field") are built in; write a custom rule with access to the full record via the third data argument passed to RuleFn if you need that.
  • regex: rule arguments cannot contain a literal | (the rule-string delimiter) or : beyond the first — for complex patterns, register a custom rule instead of using the regex: shorthand.
  • Not a coercion/transform library — it validates the value as given, it doesn't parse strings into numbers/booleans for you first.

Sponsored by Ferrow


Part of the ferrow-toolkit collection · Sponsored by Ferrow