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

@bernierllc/validators-core

v0.1.1

Published

Core types, interfaces, and utilities for the BernierLLC validators ecosystem

Readme

@bernierllc/validators-core

Core types, interfaces, and utilities for the BernierLLC validators ecosystem. This package provides the foundational building blocks for creating atomic, composable validation primitives.

Installation

npm install @bernierllc/validators-core

Usage

Creating a Validation Rule

import { defineRule, type SharedUtils } from '@bernierllc/validators-core';

const duplicateIdRule = defineRule({
  meta: {
    id: 'html/duplicate-ids',
    title: 'HTML elements must have unique IDs',
    description: 'Duplicate IDs can cause accessibility and JavaScript issues',
    domain: 'parsing',
    docsUrl: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id',
    tags: ['html', 'accessibility'],
    fixable: false,
  },
  create: (ctx) => (htmlContent: string) => {
    const doc = ctx.utils.parseHtml(htmlContent);
    if (!doc) return;
    
    const ids = new Set<string>();
    const elements = doc.querySelectorAll('[id]');
    
    elements.forEach((element) => {
      const id = element.getAttribute('id');
      if (id && ids.has(id)) {
        ctx.report({
          message: `Duplicate ID '${id}' found`,
          severity: 'error',
          domain: 'parsing',
          location: {
            selector: `#${id}`,
          },
          suggestion: `Change one of the elements with ID '${id}' to use a unique ID`,
        });
      }
      if (id) ids.add(id);
    });
  },
});

Creating a Primitive Validator

import { createPrimitiveValidator } from '@bernierllc/validators-core';

const htmlSyntaxValidator = createPrimitiveValidator(
  'html-syntax-validator',
  'parsing',
  [
    duplicateIdRule,
    malformedTagsRule,
    invalidAttributesRule,
  ]
);

// Use the validator
const context = createRuleContext('html-validation', {}, utils);
const problems = await htmlSyntaxValidator.validate(htmlContent, context);

Working with Problems and Results

import type { Problem, ValidationResult } from '@bernierllc/validators-core';

function processValidationResult(result: ValidationResult): void {
  const { problems, stats } = result;
  
  const errors = problems.filter(p => p.severity === 'error');
  const warnings = problems.filter(p => p.severity === 'warn');
  
  console.log(`Found ${errors.length} errors and ${warnings.length} warnings`);
  console.log(`Validation took ${stats.durationMs}ms`);
  
  problems.forEach(problem => {
    console.log(`${problem.severity}: ${problem.message}`);
    if (problem.location) {
      console.log(`  Location: ${problem.location.file}:${problem.location.line}`);
    }
    if (problem.suggestion) {
      console.log(`  Suggestion: ${problem.suggestion}`);
    }
  });
}

API Reference

Types

Severity

type Severity = 'off' | 'info' | 'warn' | 'error';

ValidationDomain

type ValidationDomain = 'parsing' | 'security' | 'schema' | 'accessibility' | 
  'content' | 'workflow' | 'release' | 'compliance' | 'performance';

Problem

interface Problem {
  ruleId: string;
  message: string;
  severity: Severity;
  domain: ValidationDomain;
  location?: {
    file?: string;
    line?: number;
    column?: number;
    selector?: string;
    xpath?: string;
  };
  docUrl?: string;
  suggestion?: string;
  fixable?: boolean;
  tags?: string[];
  evidence?: {
    snippet?: string;
    screenshot?: string;
    context?: Record<string, unknown>;
  };
}

Rule<T>

interface Rule<T = unknown> {
  meta: {
    id: string;
    title: string;
    description?: string;
    domain: ValidationDomain;
    docsUrl?: string;
    tags?: string[];
    fixable?: boolean;
    owner: string;
    createdAt: string;
    deprecatedAt?: string;
  };
  create: (ctx: RuleContext<T>) => (target: T) => Promise<void> | void;
}

Functions

defineRule<T>(definition: RuleDefinition<T>): Rule<T>

Creates a new validation rule with proper metadata and timestamps.

createRuleContext<T>(ruleId, options, utils, env): RuleContext<T>

Creates a rule execution context with utilities and reporting function.

createPrimitiveValidator<T>(name, domain, rules): PrimitiveValidator<T>

Creates a primitive validator that runs multiple rules against a target.

composeRules<T>(rules: Rule<T>[]): Rule<T>[]

Utility function for composing multiple rules together.

Architecture Principles

Pure Functions

Validators are pure functions that take input and return structured problems. They never:

  • Throw exceptions for validation failures
  • Make enforcement decisions
  • Modify the input
  • Perform side effects

Tool-Agnostic Design

Rules work in any context:

  • CLI tools
  • Web applications
  • CI/CD pipelines
  • IDE plugins
  • API services

Evidence-Rich Results

Problems include rich context for debugging:

  • Code snippets
  • Screenshots
  • Fix suggestions
  • Documentation links

Integration Status

  • Logger integration: not-applicable - Pure validation functions with no runtime logging needs. Core validation rules are stateless and side-effect free.
  • Docs-Suite: ready - TypeDoc compatible documentation format
  • NeverHub integration: not-applicable - Foundation package providing core types and interfaces only. Service orchestration packages will handle NeverHub integration for validation execution.

See Also

License

Copyright (c) 2025 Bernier LLC. All rights reserved.