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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@costilladante/password-validator

v1.0.0

Published

A customizable React password validator component with accessibility features

Readme

React Password Validator

npm version npm bundle size npm downloads License: MIT TypeScript React

A customizable React password validator component with accessibility features.

✨ Features

  • 🎯 Flexible Rules: Create your own password rules or use our pre-built ones
  • Accessibility First: Works with screen readers and keyboard navigation
  • 🎨 Style It Your Way: Customize the look and feel to match your app
  • 📱 Mobile Friendly: Looks great on any device
  • 🧪 Well Tested: We've got your back with comprehensive tests

Tech Stack

  • Build Tool: Vite
  • Language: TypeScript
  • UI Library: React
  • Styling: Sass (SCSS), CSS Modules, CSS variables
  • Testing: Vitest, React Testing Library
  • Linting/Formatting: ESLint (Airbnb base, Prettier), Stylelint (SCSS)
  • Git Hooks: Husky, lint-staged
  • Commit Conventions: (Optional) Conventional Commits

Accessibility

The component includes:

  • Screen reader support with ARIA attributes
  • Live updates for validation changes
  • Full keyboard navigation
  • Semantic HTML structure

🚀 Quick Start

First, install it:

npm install @costilladante/password-validator
# or
yarn add @costilladante/password-validator
# or
pnpm add @costilladante/password-validator

ℹ You will need to import the styles in your main file (usually at the root of your project, like main.tsx).

import { PasswordValidator, defaultRules, FunctionRule } from '@costilladante/password-validator'
import '@costilladante/password-validator/style.css'

const customRule = new FunctionRule(
  'customRule', // name of your rule
  'Password must be longer than 10 characters', // a message of the requirements
  (password: string) => password.length > 10, // the validator function. Can also be a RegEx!
)

const customRuleSet: RuleSet = new RuleSet([...defaultRules.rules, customRule])

function App() {
  return (
    <PasswordValidator
      ruleSet={customRuleSet}
      // Optional props
      indicators={{
        valid: '✓',
        invalid: '✗',
      }}
      className="custom-container"
      inputClassName="custom-input"
      indicatorClassName="custom-indicator"
    />
  )
}

🎮 Examples

Basic Usage

Use the pre-built rules by default.

<PasswordValidator ruleSet={defaultRules} />

Custom Rules

You can create rules that validate a function or RegEx and show a message.

import { RuleSet } from '@costilladante/password-validator'

const myRules: RuleSet = {
  rules: [
    {
      name: 'length',
      message: 'At least 8 characters please!',
      validate: (password) => (password.length >= 8 ? null : 'Too short!'),
    },
    {
      name: 'uppercase',
      message: 'Need at least one BIG letter',
      validate: (password) => (/[A-Z]/.test(password) ? null : 'No uppercase found!'),
    },
    {
      name: 'special',
      message: 'Add a special character (!@#$%)',
      validate: (password) => (/[!@#$%]/.test(password) ? null : 'Missing special character!'),
    },
  ],
}

function App() {
  return <PasswordValidator ruleSet={myRules} />
}

Custom Styling

You can easily customize the component.

<PasswordValidator
  ruleSet={defaultRules}
  className="my-container"
  inputClassName="my-input"
  indicatorsClassName="my-indicators"
  indicatorItemClassName="my-indicator-item"
/>

🛠️ Props

| Prop | Type | Required | Default | Description | | -------------------------- | ------------------------------------------------------ | -------- | ------------------------------ | --------------------- | | ruleSet | RuleSet | Yes | - | Your password rules | | indicators | { valid?: React.ReactNode, invalid?: React.ReactNode } | No | { valid: '✅', invalid: '❌' } | Custom checkmarks | | className | string | No | - | Container class | | inputClassName | string | No | - | Input field class | | indicatorsClassName | string | No | - | Rules list class | | indicatorItemClassName | string | No | - | Individual rule class |

🎨 Styling

The component uses CSS modules, so you can easily override the default styles.

.my-container {
  max-width: 400px;
  margin: 20px auto;
}

.my-input {
  width: 100%;
  padding: 10px;
  border: 2px solid #ccc;
  border-radius: 4px;

  &:focus {
    border-color: #007bff;
    outline: none;
  }
}

.my-indicators {
  margin-top: 10px;
  padding: 0;
  list-style: none;
}

.my-indicator-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
  color: #666;

  &.valid {
    color: #4e28a7;
  }

  &.invalid {
    color: #c48322;
  }
}

💻 Development

Want to play around with the code? Here's how to get started:

# Clone the repo
git clone https://github.com/yourusername/password-validator.git
cd password-validator

# Install dependencies
pnpm install

# Start the development server
pnpm dev

# Run tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Check test coverage
pnpm test:coverage

# Build the library
pnpm build

# Lint your code
pnpm lint

# Lint your styles
pnpm stylelint

# Format your code
pnpm format

📝 License

MIT - Feel free to use this in your projects!