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

@seip/validate

v0.0.2

Published

Validate requests forms with translate

Readme

Validate-Seip

A lightweight, framework-agnostic JavaScript validation library with built-in internationalization support for Express.js, Next.js, SvelteKit, and other Node.js frameworks.

Features

  • Framework Agnostic - Works with Express.js, Next.js, SvelteKit, and any framework that uses request/response patterns
  • 🌍 Multi-language Support - Built-in support for English, Spanish, Portuguese, and French
  • 🎯 Comprehensive Validation Rules - Email, URL, password strength, numeric, alpha, alphanumeric, date, and more
  • 🔧 Customizable Messages - Override default messages with your own
  • 🚀 Zero Dependencies - Lightweight and fast
  • 📦 ES Module - Modern JavaScript module system

Installation

npm i @seip/validate

Quick Start

import { Validator } from '@seip/validate';

// Define your validation schema
const userSchema = {
    email: { required: true, email: true },
    password: { required: true, password: true, min: 6 },
    name: { required: true, min: 3, max: 50 },
    age: { number: true },
    website: { url: true },
    role: { in: ['admin', 'user', 'guest'] },
    terms: { boolean: true, equals: true }
};

// Create a validator instance
const validator = new Validator(userSchema, 'en');

// Validate a request
const result = await validator.validate(req);

if (!result.success) {
    console.log(result.errors); // Array of error messages
}

Usage Examples

Express.js Middleware

import express from 'express';
import { Validator } from '@seip/validate';

const app = express();
app.use(express.json());

const loginSchema = {
    email: { required: true, email: true },
    password: { required: true, min: 6 }
};

const loginValidator = new Validator(loginSchema, 'en');

app.post('/login', loginValidator.middleware(), (req, res) => {
    res.json({ message: 'Login successful' });
});

Next.js API Route

import { Validator } from '@seip/validate';

const registerSchema = {
    email: { required: true, email: true },
    password: { required: true, password: true },
    name: { required: true, min: 3 }
};

export default async function handler(req, res) {
    const validator = new Validator(registerSchema, 'en');
    const result = await validator.validate(req);
    
    if (!result.success) {
        return res.status(400).json(result);
    }
    
    // Process registration...
    res.status(200).json({ message: 'Registration successful' });
}

SvelteKit

import { Validator } from '@seip/validate';

const profileSchema = {
    name: { required: true, min: 3, max: 50 },
    bio: { max: 500 },
    website: { url: true }
};

export const actions = {
    default: async ({ request }) => {
        const formData = await request.formData();
        const req = {
            body: Object.fromEntries(formData)
        };
        
        const validator = new Validator(profileSchema, 'en');
        const result = await validator.validate(req);
        
        if (!result.success) {
            return { errors: result.errors };
        }
        
        // Process form...
        return { success: true };
    }
};

Validation Rules

| Rule | Description | Example | |------|-------------|---------| | required | Field must be present and not empty | { required: true } | | min | Minimum string length | { min: 6 } | | max | Maximum string length | { max: 50 } | | email | Valid email format | { email: true } | | number | Numeric value | { number: true } | | alpha | Only letters (a-z, A-Z) | { alpha: true } | | alphanumeric | Letters and numbers only | { alphanumeric: true } | | boolean | Boolean value | { boolean: true } | | date | Valid ISO 8601 date | { date: true } | | url | Valid URL format | { url: true } | | in | Value must be in array | { in: ['admin', 'user'] } | | equals | Value must equal specific value | { equals: true } | | password | Strong password (uppercase, lowercase, numbers, min 6 chars) | { password: true } | | pattern | Custom regex pattern | { pattern: /^[A-Z]/ } |

Supported Languages

The library supports the following languages out of the box:

  • English (en)
  • Spanish (es)
  • Portuguese (pt)
  • French (fr)

Setting Language

// Set language explicitly
const validator = new Validator(schema, 'en');

// Use session language (falls back to Spanish if not set)
const validator = new Validator(schema);
const result = await validator.validate(req); // Uses req.session.lang if available

Custom Error Messages

You can override default error messages in two ways:

1. Per-field Custom Messages

const schema = {
    email: {
        required: true,
        email: true,
        messages: {
            required: 'Please provide your email address',
            email: 'That doesn\'t look like a valid email'
        }
    }
};

2. Global Custom Messages

const customMessages = {
    en: {
        required: (field) => `${field} is mandatory`,
        email: (field) => `Please enter a valid email for ${field}`,
        // ... other rules
    }
};

const validator = new Validator(schema, 'en', customMessages);

Response Format

Success Response

{
    success: true,
    errors: [],
    message: [],
    html: []
}

Error Response

{
    success: false,
    errors: [
        "email is required",
        "password must be at least 6 characters"
    ],
    message: [
        "email is required",
        "password must be at least 6 characters"
    ],
    html: [
        '<p class="text-red-500 text-danger">email is required</p>',
        '<p class="text-red-500 text-danger">password must be at least 6 characters</p>'
    ]
}

Advanced Examples

Combining Multiple Rules

const schema = {
    username: {
        required: true,
        alphanumeric: true,
        min: 3,
        max: 20
    },
    password: {
        required: true,
        password: true,
        min: 8
    },
    confirmPassword: {
        required: true,
        equals: req.body.password // Must match password field
    }
};

Custom Pattern Validation

const schema = {
    zipCode: {
        required: true,
        pattern: /^\d{5}(-\d{4})?$/ // US ZIP code format
    },
    phoneNumber: {
        pattern: /^\+?[\d\s-()]+$/ // International phone format
    }
};

Testing

Run the included test suite:

node test.js

The test file demonstrates validation in all supported languages with various scenarios.

API Reference

Validator Class

Constructor

new Validator(schema, lang_default = null, messages = null)
  • schema (Object): Validation schema defining rules for each field
  • lang_default (String, optional): Default language code ('en', 'es', 'pt', 'fr')
  • messages (Object, optional): Custom error messages object

Methods

validate(req)

Validates the request body against the schema.

  • Parameters: req - Request object with body property
  • Returns: Promise resolving to validation result object
middleware()

Returns an Express.js middleware function that automatically validates and returns 400 status on validation failure.

  • Returns: Express middleware function

License

MIT

Author

Seip25

Repository

https://github.com/seip25/validate

Contributing

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

Support

For issues and questions, please use the GitHub Issues page.