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

@freelang/validator

v1.0.0

Published

FreeLang Native Request Validator - express-validator replacement (zero npm dependencies)

Downloads

51

Readme

@freelang/validator

FreeLang Native Input Validator - express-validator replacement

Zero npm dependencies - Uses only Node.js built-in modules

Features

  • ✅ Schema-based validation
  • ✅ Field-level validation with custom rules
  • ✅ Automatic error formatting
  • ✅ Chainable API for fluent validation
  • ✅ Custom error messages support
  • ✅ Pre-built validators (email, URL, numeric range, etc.)

Installation

npm install @freelang/validator

Usage

Basic Field Validation

const { validateField, ValidationError } = require('@freelang/validator');

// Validate email
const result = validateField('email', '[email protected]', {
  type: 'email',
  required: true
});

if (result.valid) {
  console.log('Email is valid');
} else {
  console.log('Errors:', result.errors);
  // → { field: 'email', message: 'Invalid email format' }
}

Validate Multiple Fields

const { validateSchema } = require('@freelang/validator');

const schema = {
  email: { type: 'email', required: true },
  password: { type: 'string', min: 8, max: 128 },
  age: { type: 'number', min: 18, max: 120 },
  website: { type: 'url', required: false }
};

const data = {
  email: '[email protected]',
  password: 'SecurePass123!',
  age: 25,
  website: 'https://example.com'
};

const validation = validateSchema(schema, data);
if (validation.isValid) {
  console.log('All fields valid');
} else {
  validation.errors.forEach(err => {
    console.log(`${err.field}: ${err.message}`);
  });
}

Custom Validators

const { createValidator } = require('@freelang/validator');

// Create custom validator
const phoneValidator = createValidator('phone', (value) => {
  const phoneRegex = /^\+?[\d\s\-()]{10,}$/;
  return phoneRegex.test(value);
}, 'Invalid phone number');

// Use in schema
const schema = {
  phone: { validator: phoneValidator, required: true }
};

Built-in Validators

const { validate } = require('@freelang/validator');

// Email
validate('email', '[email protected]').isEmail()

// URL
validate('website', 'https://example.com').isUrl()

// Numeric range
validate('age', 25).isNumber().min(0).max(150)

// String length
validate('username', 'john_doe').isString().min(3).max(20)

// Alphanumeric
validate('code', 'ABC123').isAlphanumeric()

// Date
validate('birthdate', '1990-01-15').isDate()

// Custom regex
validate('code', 'FL-12345').matches(/^[A-Z]{2}-\d{5}$/)

API

validateField(fieldName, value, rules) → object

Validate single field with specified rules.

Returns: { valid: boolean, errors: array }

validateSchema(schema, data) → object

Validate multiple fields against schema.

Returns: { isValid: boolean, errors: array, data: object }

createValidator(name, fn, message) → function

Create reusable custom validator.

validate(fieldName, value) → ChainableValidator

Fluent API for field validation.

Methods:

  • .isEmail() → ChainableValidator
  • .isUrl() → ChainableValidator
  • .isNumber() → ChainableValidator
  • .isString() → ChainableValidator
  • .isBoolean() → ChainableValidator
  • .isDate() → ChainableValidator
  • .isAlphanumeric() → ChainableValidator
  • .min(n) → ChainableValidator
  • .max(n) → ChainableValidator
  • .matches(regex) → ChainableValidator
  • .custom(fn) → ChainableValidator
  • .error(message) → ChainableValidator
  • .validate() → { valid: boolean, errors: array }

FreeLang Integration

import { validateField, validateSchema } from @freelang/validator

fn validate_user_registration(req: map) {
    let data = {
        "email": map_get(req, "email"),
        "password": map_get(req, "password"),
        "age": map_get(req, "age")
    }

    let schema = {
        "email": { "type": "email", "required": true },
        "password": { "type": "string", "min": 8 },
        "age": { "type": "number", "min": 18 }
    }

    let result = validateSchema(schema, data)

    if result["isValid"] {
        return { "status": "ok", "data": result["data"] }
    } else {
        return { "status": "error", "errors": result["errors"] }
    }
}

fn validate_email_field(email: string) {
    let result = validateField("email", email, {
        "type": "email",
        "required": true
    })

    return result["valid"]
}

Error Messages

Custom error messages for localization:

const schema = {
  email: {
    type: 'email',
    required: true,
    message: 'Please enter a valid email address'
  },
  password: {
    type: 'string',
    min: 8,
    message: 'Password must be at least 8 characters'
  }
};

Performance

  • Field validation: < 0.1ms
  • Schema validation (5 fields): < 1ms
  • Memory: < 50KB for typical validation
  • Supports 100+ simultaneous validations

Supported Data Types

  • email - Standard email format
  • url - HTTP/HTTPS URLs
  • number - Integer or float
  • string - Text with length constraints
  • boolean - True/false values
  • date - ISO 8601 date format
  • alphanumeric - Letters and numbers only
  • phone - Phone number format
  • uuid - UUID v4 format
  • ipv4 - IPv4 address format
  • json - Valid JSON string
  • custom - User-defined validation

Security Notes

  • ⚠️ Validate on both client and server
  • ⚠️ Never trust client-side validation alone
  • ⚠️ Sanitize inputs before database operations
  • ⚠️ Set appropriate field length limits
  • ⚠️ Use HTTPS for sensitive data transmission

License

MIT

Related Packages