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

int-validate

v1.0.9

Published

Validator

Readme

Field Validator

A lightweight, flexible, and chainable validation library for Node.js applications that provides robust validation rules for common data types and formats. Built with safety and usability in mind.

Features

  • 🔗 Chainable validation rules
  • 🌍 Locale-specific validations
  • 🔒 Strong password validation
  • 📝 Comprehensive error reporting
  • 🛡️ Built-in type safety
  • 🧩 Extensible architecture
  • 0️⃣ Zero external dependencies

Installation

npm install int-validate

Quick Start

const validator = require('int-validate')();

// Define validation schema
const schema = {
    email: validator.required().email().set(),
    password: validator.required().password().set()
};

// Data to validate
const data = {
    email: '[email protected]',
    password: 'SecureP@ss123'
};

// Perform validation
const result = validator.validate(schema, data);
console.log(result.valid ? 'Valid!' : result.errors);

Validation Rules

Text Validation

| Validator | Description | Example | |-----------|-------------|---------| | alpha(locale?) | Letters only | validator.alpha('en-US') | | alphanumeric(locale?) | Letters and numbers | validator.alphanumeric('en-US') | | length(min, max) | String length range | validator.length(3, 20) | | contains(field) | Contains another field's value | validator.contains('description') | | matches(field) | Exact match with another field | validator.matches('password') |

Number Validation

| Validator | Description | Example | |-----------|-------------|---------| | numeric() | Numbers only | validator.numeric() | | decimal() | Decimal numbers | validator.decimal() |

Special Types

| Validator | Description | Example | |-----------|-------------|---------| | email() | Email addresses | validator.email() | | password() | Strong passwords | validator.password() | | creditCard() | Credit card numbers | validator.creditCard() | | phone(locale) | Phone numbers | validator.phone('en-US') | | postalCode(locale) | Postal codes | validator.postalCode('US') |

Other Validators

| Validator | Description | Example | |-----------|-------------|---------| | base64() | Base64 strings | validator.base64() | | boolean() | Boolean values | validator.boolean() | | date() | Date strings | validator.date() | | time() | Time strings | validator.time() | | required() | Required fields | validator.required() |

Password Validation Rules

The password validator enforces the following security rules:

  • Minimum length of 8 characters
  • At least one lowercase letter (a-z)
  • At least one uppercase letter (A-Z)
  • At least one number (0-9)
  • At least one special character (~`!#$%^&*+=-[]\',/{}|":<>?)

Common Use Cases

User Registration Form

const registrationSchema = {
    username: validator
        .required()
        .alphanumeric()
        .length(3, 20)
        .set(),
    email: validator
        .required()
        .email()
        .set(),
    password: validator
        .required()
        .password()
        .set(),
    confirmPassword: validator
        .required()
        .matches('password')
        .set()
};

Payment Form

const paymentSchema = {
    cardNumber: validator
        .required()
        .creditCard()
        .set(),
    expiryDate: validator
        .required()
        .date()
        .set(),
    cvv: validator
        .required()
        .numeric()
        .length(3, 4)
        .set()
};

Address Validation

const addressSchema = {
    streetName: validator
        .required()
        .alpha()
        .set(),
    houseNumber: validator
        .required()
        .numeric()
        .set(),
    postalCode: validator
        .required()
        .postalCode('US')
        .set()
};

Validation Response

The validation function returns an object with the following structure:

{
    valid: boolean,
    errors: [
        {
            field: string,
            message: string
        }
    ]
}

Example error response:

{
    valid: false,
    errors: [
        {
            field: "password",
            message: "Not a strong enough password. Needs 8 characters with at least a number, lowercase, uppercase and special character."
        }
    ]
}

Best Practices

  1. Chain Validators
// Good
const schema = {
    username: validator
        .required()
        .alphanumeric()
        .length(3, 20)
        .set()
};

// Avoid
const schema = {
    username: [...validator.required().set(), 
               ...validator.alphanumeric().set()]
};
  1. Clear Validators After Use
// Validators are automatically cleared after .set()
const commonValidators = validator
    .required()
    .length(3, 20)
    .set();
  1. Handle Validation Results
const result = validator.validate(schema, data);
if (!result.valid) {
    result.errors.forEach(error => {
        console.log(`${error.field}: ${error.message}`);
    });
}

Error Messages

Default error messages are provided for each validation type. Examples:

{
    required: "Required field",
    email: "Not a valid e-mail address",
    password: "Not a strong enough password. Needs 8 characters with at least a number, lowercase, uppercase and special character.",
    // ... other messages
}

Type Safety

The validator includes built-in type safety features:

  • Safe string conversion
  • Null/undefined handling
  • Type checking for inputs

Performance Considerations

  • Validators are cleared after each set() call
  • Efficient string manipulation
  • Optimized regex patterns
  • Minimal memory footprint

Browser Support

The validator is primarily designed for Node.js applications but can be used in modern browsers with appropriate bundling.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Author

Gregory - Genie