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

@rolster/validators

v3.1.2

Published

Utility lightweight simple for apply data validations.

Downloads

1,287

Readme

Rolster Validators

Utility lightweight simple for apply data validations.

Installation

npm i @rolster/validators

Configuration

You must install the @rolster/types to define package data types, which are configured by adding them to the files property of the tsconfig.json file.

{
  "files": ["node_modules/@rolster/types/index.d.ts"]
}

Concepts

A validator is a function that receives a value and returns either undefined (the value is valid) or a ValidatorError describing the problem:

interface ValidatorError<T = any> {
  id: string; // unique error identifier, e.g. 'required'
  message: string; // human readable message (i18n, es/en)
  data?: T; // extra context about the failure
}

The library ships with three entry points:

  • @rolster/validators — the validate function to validate whole objects.
  • @rolster/validators/helpers — the catalog of ready-to-use validators.
  • @rolster/validators/expressions — the underlying regular expressions.

Features

Built-in validators

Import them from @rolster/validators/helpers. Each returns a ValidatorError when the value is invalid, or undefined when it is valid.

Presence

| Validator | Valid when… | | ---------------------- | ------------------------------------ | | defined(value) | value is not null/undefined | | required(value) | value is truthy | | checked(value) | boolean value is true |

Text format

| Validator | Valid when… | | ----------------------- | ------------------------------------------------- | | textonly(value) | only letters, no spaces | | alphabetic(value) | only letters and spaces | | alphanumber(value) | only letters and numbers | | onlyNumber(value) | only digits | | email(value) | valid email address | | hexColor(value) | hexadecimal color (#RRGGBB / #RRGGBBAA) | | nickname(value) | valid username (letters, numbers, . _ - @) | | password(value) | only the allowed password characters | | decimal(value) | decimal number |

Length (factory validators)

| Validator | Valid when… | | ------------------------- | ------------------------------------ | | strReqlength(n) | string length is exactly n | | strMinlength(n) | string length is at least n | | strMaxlength(n) | string length is at most n |

Numeric range (factory validators)

| Validator | Valid when… | | ------------------------------ | ------------------------ | | minValue(n) | value >= n | | maxValue(n) | value <= n | | greaterThanValue(n) | value > n | | greaterOrEqualsThanValue(n) | value >= n | | lessThanValue(n) | value < n | | lessOrEqualsThanValue(n) | value <= n |

import { required, email, strMinlength } from '@rolster/validators/helpers';

required(''); // { id: 'required', message: 'Field is required', ... }
required('Daniel'); // undefined

email('not-an-email'); // { id: 'email', message: 'Field must be email', ... }
email('[email protected]'); // undefined

const min = strMinlength(8);
min('123'); // { id: 'strMinlength', ... }
min('12345678'); // undefined

Validating an object

Use validate to run several validators against the fields of an object. It returns whether the object is valid plus the collected errors per field.

import { validate } from '@rolster/validators';
import { required, email, strMinlength } from '@rolster/validators/helpers';

const form = { name: '', email: '[email protected]', password: '123' };

const result = validate(form, {
  name: [required],
  email: [required, email],
  password: [required, strMinlength(8)]
});

result.valid; // false
result.errors;
// {
//   name: [{ id: 'required', message: 'Field is required', ... }],
//   password: [{ id: 'strMinlength', message: 'Field must have minimum 8 characters', ... }]
// }

Internationalized messages

Error messages are localized through @rolster/i18n and ship with Spanish (es) and English (en) translations out of the box.

Regular expressions

If you only need the raw patterns (for inputs, masks, etc.) import them from @rolster/validators/expressions:

import { REGEX_EMAIL, REGEX_HEX_COLOR } from '@rolster/validators/expressions';

REGEX_EMAIL.test('[email protected]'); // true

Contributing

  • Daniel Andrés Castillo Pedroza :rocket: