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

bean-validator

v1.0.2

Published

A http request validation

Readme

Request Validation for JavaScript — inspired by Jakarta Bean Validation (JSR 380) and Hibernate Validator constraints.

This package allows you to define validation rules at runtime directly in your DTO classes without decorators, without TypeScript, and without boilerplate.

Installation

npm install bean-validator

Features

  • No decorators, works in pure JavaScript
  • Clean Architecture, separates rules from validation logic
  • Supports Jakarta + Hibernate constraints
  • Runtime definition like Lombok’s annotations in Java
  • Custom validators supported

Basic Usage

const { defineField, validate, NOT_EMPTY, EMAIL } = require("bean-validator");

class UserDTO {
  constructor(name, email) {
    defineField(this, "name", name, [
      { type: NOT_EMPTY, message: "Name is required" }
    ]);
    defineField(this, "email", email, [
      { type: NOT_EMPTY, message: "Email is required" },
      { type: EMAIL, message: "Invalid email format" }
    ]);
  }
}

const user = new UserDTO("", "bad-email");
console.log(validate(user));

Output:

{
  "name": ["Name is required"],
  "email": ["Invalid email format"]
}

Supported Validators

| Constant | Description | | ----------- | ---------------------------------------------------- | | DIGITS | Value has at most given integer and fraction digits. | | EMAIL | Valid email address. | | MAX | Numeric value ≤ given max. | | MIN | Numeric value ≥ given min. | | NOT_BLANK | String is not null and trimmed length > 0. | | NOT_EMPTY | Value (string/array) is not null and length > 0. | | NOT_NULL | Value is not null or undefined. | | PATTERN | String matches given regex. | | SIZE | Array/string length between given min and max. | | CREDIT_CARD_NUMBER | Valid credit card number (Luhn algorithm). | | LENGTH | String length between given min and max. | | CURRENCY | Valid currency format. | | RANGE | Numeric value between given min and max. | | URL | Valid URL. | | UNIQUE_ELEMENTS | Array contains only unique elements. | | EAN | Valid EAN-8 or EAN-13 barcode. | | ISBN | Valid ISBN-10 or ISBN-13 code. |

Passing Parameters to Validators

Some validators require parameters. You pass them via params in the rule:

const { defineField, validate, DIGITS, RANGE } = require("bean-validator");

class ProductDTO {
  constructor(price, rating) {
    defineField(this, "price", price, [
      { type: DIGITS, message: "Max 5 integer and 2 fraction digits", params: { integer: 5, fraction: 2 } }
    ]);
    defineField(this, "rating", rating, [
      { type: RANGE, message: "Rating must be between 1 and 5", params: { min: 1, max: 5 } }
    ]);
  }
}

const product = new ProductDTO("123456.78", 6);
console.log(validate(product));

Creating Custom Validators

const { defineField, validate } = require("bean-validator");
const { registerValidator } = require("bean-validator");

// 1. Register custom validator
registerValidator("startsWithA", (value) => value?.startsWith("A"));

// 2. Use in DTO
class CategoryDTO {
  constructor(name) {
    defineField(this, "name", name, [
      { type: "startsWithA", message: "Name must start with 'A'" }
    ]);
  }
}

const category = new CategoryDTO("Banana");
console.log(validate(category));

License

MIT