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

ctrovalidate-browser

v1.0.0

Published

Browser adapter for Ctrovalidate - Declarative HTML-first form validation with data attributes.

Readme

ctrovalidate-browser

DOM-first validation for vanilla JavaScript and HTML.

ctrovalidate-browser provides a Ctrovalidate controller class that bridges ctrovalidate-core validation logic to the DOM. Discover fields via data attributes, manage event listeners, display errors, and handle ARIA accessibility — all without a framework.

npm version License: MIT


Installation

npm install ctrovalidate-browser ctrovalidate-core

Quick Start

HTML

<form id="signupForm" novalidate>
  <div>
    <input
      type="email"
      name="email"
      data-ctrovalidate-rules="required|email"
    />
    <div class="error-message"></div>
  </div>

  <div>
    <input
      type="password"
      name="password"
      data-ctrovalidate-rules="required|minLength:8|strongPassword"
    />
    <div class="error-message"></div>
  </div>

  <button type="submit">Sign Up</button>
</form>

JavaScript

import { Ctrovalidate } from 'ctrovalidate-browser';

const form = document.querySelector('#signupForm');
const validator = new Ctrovalidate(form, {
  errorClass: 'is-invalid',
  errorMessageClass: 'error-message',
});

form.addEventListener('submit', async (e) => {
  e.preventDefault();
  const isValid = await validator.validate();
  if (isValid) {
    // Submit
  }
});

Data Attributes

| Attribute | Description | |-----------|-------------| | data-ctrovalidate-rules | Pipe-delimited rule string (e.g. required\|email\|minLength:8) | | data-ctrovalidate-if | Conditional validation dependency (e.g. agreeTerms:checked, country:value=USA) | | data-ctrovalidate-message | Catch-all error message for the field | | data-ctrovalidate-{ruleName}-message | Rule-specific error message |


Configuration

const validator = new Ctrovalidate(form, {
  realTime: true,                          // Enable blur/input listeners
  errorClass: 'is-invalid border-red-500', // Supports Tailwind space-separated
  errorMessageClass: 'error-message',      // Also space-separated
  pendingClass: 'is-validating',           // Added during async validation
  logLevel: Ctrovalidate.LogLevel.NONE,    // Logging verbosity
  schema: { email: 'required|email' },     // Programmatic rules (merged with HTML)
  aliases: { username: 'required|alphaDash|minLength:3' }, // Instance aliases
});

Instance Methods

await validator.validate();            // Validate all fields
validator.addField(element);           // Register a field
validator.removeField(element);         // Unregister a field
validator.refresh();                    // Re-discover fields
validator.isDirty('email');             // Check if field was interacted with
validator.getError('email');            // Get current error message
validator.reset();                      // Clear all validation state
validator.destroy();                    // Full cleanup

Static Methods

Ctrovalidate.defineAlias('password', 'required|minLength:8|strongPassword');
Ctrovalidate.addRule('isEven', (v) => Number(v) % 2 === 0, 'Must be even.');
Ctrovalidate.addAsyncRule('checkEmail', async (v, p, el, signal) => { ... });
Ctrovalidate.setCustomMessages({ required: 'Cannot be empty.' });

Accessibility

The controller automatically manages:

  • aria-invalid="true" on validation failure
  • aria-describedby linking to the error container
  • role="status" and aria-live="polite" on fallback error containers

Related Packages


License

MIT © Ctrotech

Full documentation: https://ctrovalidate.vercel.app