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

@seij/common-validation

v0.1.2

Published

Small validation primitives and constraint types used across Seij applications.

Readme

common-validation

Small validation primitives and constraint types used across Seij applications.

Concept

The library lets you define field validation rules as data, then evaluate them the same way in every form. A validation result is { valid, error, severity } where severity is BLOCKER (cannot save) or WARNING (show message but allow save). This keeps UI validation consistent and easy to share.

Example: fields with rules

const fields = [
  {
    key: "age",
    label: "Age",
    type: "number",
    rules: [
      { code: "REQUIRED", severity: "BLOCKER" },
      { code: "MIN", value: 10, severity: "BLOCKER" },
      { code: "MIN", value: 18, severity: "WARNING" },
    ],
  },
  {
    key: "registered",
    label: "Registered at",
    type: "localdate",
    rules: [{ code: "TODAY", todayConstraint: "LOWER_OR_EQUALS", severity: "BLOCKER" }],
  },
  {
    key: "recall",
    label: "Recall customer at",
    type: "localdate",
    rules: [{ code: "TODAY", todayConstraint: "GREATER", severity: "BLOCKER" }],
  },
];

Mini guide: validate a form in practice

1) Validate a field using its rules

import {
  valid,
  invalid,
  createComparator,
  createComparatorMessageToken,
  createValidationMessage,
  type RuleConstraintValueRequired,
  type RuleConstraintValueMin,
  type RuleConstraintValueMax,
  type RuleConstraintValueToday,
} from "@seij/common-validation";
import type { LocalDate } from "@seij/common-types";

type NumberRule = RuleConstraintValueRequired<number> | RuleConstraintValueMin<number> | RuleConstraintValueMax<number>;

type DateRule = RuleConstraintValueToday;

function validateNumber(value: number | null | undefined, rules: NumberRule[]) {
  for (const rule of rules) {
    if (rule.code === "REQUIRED" && (value === null || value === undefined)) {
      return invalid(rule.message ?? "Value is required", rule.severity);
    }
    if (rule.code === "MIN" && value !== null && value !== undefined) {
      if (value >= rule.value) continue;
      const msg = createValidationMessage(rule.message, "Value must be >= {1}", String(rule.value));
      return invalid(msg, rule.severity);
    }
    if (rule.code === "MAX" && value !== null && value !== undefined) {
      if (value <= rule.value) continue;
      const msg = createValidationMessage(rule.message, "Value must be <= {1}", String(rule.value));
      return invalid(msg, rule.severity);
    }
  }
  return valid;
}

function validateDate(value: LocalDate | null | undefined, rules: DateRule[], today: LocalDate) {
  for (const rule of rules) {
    if (rule.code === "TODAY" && value) {
      const ok = createComparator(rule.todayConstraint)(value, today);
      if (ok) continue;
      const token = createComparatorMessageToken(rule.todayConstraint);
      const msg = createValidationMessage(rule.message, "Date must be {1} today", token);
      return invalid(msg, rule.severity);
    }
  }
  return valid;
}

2) Aggregate results to drive the form UI

import { combineValidationResults } from "@seij/common-validation";

const ageResult = validateNumber(form.age, fields[0].rules);
const registeredResult = validateDate(form.registered, fields[1].rules, today);
const recallResult = validateDate(form.recall, fields[2].rules, today);

const formResult = combineValidationResults([ageResult, registeredResult, recallResult]);
const hasBlockingError = !formResult.valid && formResult.severity === "BLOCKER";

Typical UI usage:

  • Show formResult.error near the field or in a summary.
  • Disable submit when hasBlockingError is true.
  • For WARNING, show a message but allow the user to save.
  • LocalDate is always YYYY-MM-DD, so string comparison is safe. (see @seij/common-types)