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

@arikajs/validation

v0.10.19

Published

Powerful, expressive validation system for the ArikaJS framework.

Readme

Arika Validation

@arikajs/validation provides a powerful, expressive validation system for the ArikaJS framework.

It allows developers to validate incoming data using declarative rules, handle errors consistently, and integrate validation seamlessly into controllers and middleware.

import { Validator } from '@arikajs/validation';

const validator = new Validator(
  {
    email: '[email protected]',
    password: 'secret123'
  },
  {
    email: 'required|email',
    password: 'required|min:8'
  }
);

if (validator.fails()) {
  console.log(validator.errors());
}

Status

  • Stage: Experimental / v0.x
  • Scope (v0.x):
    • Rule-based validation syntax
    • Custom rule support
    • Multiple error messages per field
    • Async validation support
    • JS & TS friendly API
  • Out of scope (for this package):
    • Parsing HTTP requests
    • Rendering views
    • Authentication logic

🎯 Purpose

Validation protects application logic from invalid or unsafe input. This package is responsible for:

  • Validating request data (body, query, params)
  • Providing rule-based validation
  • Supporting custom validation rules
  • Returning structured validation errors
  • Integrating cleanly with HTTP and controllers

🧠 Responsibilities

✅ What Arika Validation Does

  • Validate plain JavaScript objects
  • Support string-based validation rules
  • Provide reusable rule classes
  • Collect and format validation errors
  • Allow synchronous and asynchronous rules
  • Integrate with controllers & middleware

❌ What Arika Validation Does NOT Do

  • Parse HTTP requests
  • Render views
  • Handle authentication or authorization
  • Perform database operations

Features

  • Rule-based validation syntax
    • Intuitive pipe-based rules like required|email|min:8.
  • Custom rule support
    • Easily extend the validator with your own logic.
  • Multiple error messages per field
    • Comprehensive feedback for users.
  • Async validation support
    • Validate against databases or external services.
  • Framework-agnostic core
    • Use it anywhere, not just in ArikaJS.
  • JS & TS friendly API
    • Written in TypeScript with full type definitions.

Installation

npm install @arikajs/validation
# or
yarn add @arikajs/validation
# or
pnpm add @arikajs/validation

🔎 Validation Rules

Rules are defined using a pipe-based syntax:

email: 'required|email'
password: 'required|min:8|max:32'

📦 Built-in Rules (v0.x)

| Rule | Description | | :--- | :--- | | required | Field must be present and not empty | | nullable | Field can be null or empty | | bail | Stop validation after first failure for a field | | email | Must be a valid email address | | min:value | Minimum length (string) or value (number) | | max:value | Maximum length (string) or value (number) | | string | Must be a string | | number | Must be numeric | | required_if:field,value | Required if another field matches a value | | in:foo,bar | The field under validation must be included in the given list of values | | not_in:foo,bar | The field under validation must not be included in the given list of values | | alpha | The field under validation must be entirely alphabetic characters | | alpha_num | The field under validation must be entirely alpha-numeric characters | | url | Must be a valid URL | | boolean | Must be a boolean (e.g., true, false, 1, 0) | | array | Must be a JavaScript array | | confirmed | The field must have a matching field of _confirmation (e.g. password needs password_confirmation) |

🚀 Advanced Features

  • Nested Object Validation: Use dot notation to validate deep structures (user.email).
  • Array Wildcard Validation: Use * to validate all elements in an array (users.*.email).
  • Bail Validation: Stop executing rules for a field after the first failure.
  • Validated Data: Use validator.validated() to get only the data that passed validation.
  • Conditional Rules: Rules that only run based on the values of other fields.

🧱 Custom Rules

Creating a Rule

import { Rule } from '@arikajs/validation';

export class Uppercase implements Rule {
  validate(value: any): boolean {
    return typeof value === 'string' && value === value.toUpperCase();
  }

  message(): string {
    return 'The value must be uppercase.';
  }
}

Registering a Rule

validator.extend('uppercase', new Uppercase());

Usage

name: 'required|uppercase'

❌ Validation Errors

Checking Failure

if (validator.fails()) {
  throw new ValidationError(validator.errors());
}

Error Structure

{
  "email": ["The email field is required."],
  "password": ["The password must be at least 8 characters."]
}

Customizing Error Messages

You can pass an object of custom messages as the third argument to the Validator constructor. You can override globally for a rule or target specific fields.

const validator = new Validator(data, rules, {
    'required': 'Hold up, you forgot the :attribute field!',
    'email.email': 'Dude, that is not a real email address!'
});

🔌 Framework Integration

Controller Usage

(Provided by @arikajs/http)

request.validate({
  email: 'required|email',
  password: 'required|min:8'
});

Middleware Usage

export async function validateLogin(request, next) {
  const validator = new Validator(request.body, {
    email: 'required|email',
    password: 'required'
  });

  if (validator.fails()) {
      return response.status(422).json(validator.errors());
  }

  return next(request);
}

⚙️ Advanced Usage

Async Validation

class UniqueEmail {
  async validate(value) {
    return !(await userRepo.exists(value));
  }

  message() {
    return 'Email already taken.';
  }
}

🏗 Architecture

validation/
├── src/
│   ├── Rules
│   │   ├── Alpha.ts
│   │   ├── AlphaNum.ts
│   │   ├── Boolean.ts
│   │   ├── Confirmed.ts
│   │   ├── Email.ts
│   │   ├── In.ts
│   │   ├── IsArray.ts
│   │   ├── Max.ts
│   │   ├── Min.ts
│   │   ├── NotIn.ts
│   │   ├── Number.ts
│   │   ├── Required.ts
│   │   ├── RequiredIf.ts
│   │   ├── String.ts
│   │   └── Url.ts
│   ├── ErrorBag.ts
│   ├── index.ts
│   ├── Rule.ts
│   ├── ValidationError.ts
│   └── Validator.ts
├── tests/
├── package.json
├── tsconfig.json
└── README.md

Versioning & Stability

  • Current version: v0.x (experimental)
  • API may change until v1.0
  • Will follow semantic versioning after stabilization

📜 License

@arikajs/validation is licensed under the MIT License 1.1 (MIT).


🧠 Philosophy

“Validation is not restriction — it is protection.”