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

abit-validator

v1.0.1

Published

abit-validator schema from scratch

Readme

ABIT Validator

A lightweight, type-safe validation library for JavaScript/TypeScript with a fluent API.

Installation

npm install abit-validator

Features

Type-safe validation with TypeScript support

Fluent API for building validation schemas

Support for primitive types, objects, and arrays

Custom error messages

Optional, nullable, and default values

Transformation of validated data

Composition with or operator

Basic Usage

import abitValidator from 'abit-validator';

// Create a validator
const userValidator = abitValidator.object({
  name: abitValidator.string().min(3).max(50),
  age: abitValidator.number().min(18),
  email: abitValidator.string().email(),
  isAdmin: abitValidator.boolean().optional(),
  tags: abitValidator.array(abitValidator.string()).min(1).max(5),
});

// Validate data
try {
  const user = userValidator.parse({
    name: 'John Doe',
    age: 25,
    email: '[email protected]',
    tags: ['developer', 'typescript'],
  });
  console.log('Valid user:', user);
} catch (error) {
  console.error('Validation failed:', error);
}

// Safe parse (without throwing)
const result = userValidator.safeParse(someData);
if (result.success) {
  console.log('Valid data:', result.data);
} else {
  console.error('Validation errors:', result.errors);
}

Validator Types

Primitive Validators

String Validation

| Method | Description | | ------------------------ | -------------------------------- | | abitValidator.string() | Base string validator | | .min(length) | Minimum string length | | .max(length) | Maximum string length | | .length(len) | Exact string length | | .email() | Must be a valid email format | | .startsWith(value) | Must start with a specific value | | .regex(pattern) | Must match a regular expression |

Number Validation

| Method | Description | | ------------------------ | --------------------- | | abitValidator.number() | Base number validator | | .min(value) | Minimum numeric value | | .max(value) | Maximum numeric value |

Boolean Validation

| Method | Description | | ------------------------- | ---------------------- | | abitValidator.boolean() | Base boolean validator |

Complex Validators

| Method | Description | | ------------------------------ | -------------------------------------------------- | | abitValidator.object(schema) | Validates an object based on a shape/schema object | | | (i.e. { key: validator }) |

Array Validation

| Method | Description | | -------------------------------- | ---------------------------------------------------------- | | abitValidator.array(validator) | Validates an array where all items use the given validator | | .min(length) | Minimum array length | | .max(length) | Maximum array length | | .nonempty() | Array must not be empty |

Utility Methods

| Method | Description | | ----------------------------- | ------------------------------------------------------- | | .optional() | Makes the field optional (i.e., undefined is allowed) | | .nullable() | Allows null as a valid value | | .default(value) | Provides a default value if the input is undefined | | .refine(validator, message) | Adds a custom validation with an error message | | .or(otherValidator) | Allows alternative validation if the first fails | | .transform(fn) | Transforms the validated value using a function | | .instanceof(constructor) | Checks if the value is an instance of a given class | | .enum(enumObj) | Validates that the value is one of the enum's values | | .literal(value) | Ensures the value exactly matches the given value |

Error Handling

The library throws ValidationError with detailed error information when validation fails. You can also use safeParse to get validation results without throwing.

Custom Validation

const passwordValidator = abitValidator
  .string()
  .min(8)
  .refine(
    (val) => /[A-Z]/.test(val) && /[0-9]/.test(val),
    'Password must contain at least one uppercase letter and one number',
  );

Type Safety

All validators are fully typed and preserve TypeScript type information through transformations and compositions.

License MIT