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

@lahiru.dev/check-mate

v1.0.6

Published

A TypeScript-based form validation library for React applications.

Downloads

53

Readme

@lahiru.dev/check-mate

Here’s an example of how you can structure your README.md for your Form Validation Library npm package. It follows open-source best practices, includes clear installation and usage instructions, and provides helpful examples to make it easy for developers to get started.


Form Validation Library for React

A simple, lightweight, and flexible form validation library for React applications, built with TypeScript. Easily validate form fields with custom validation rules and error messages.

🚀 Features

  • Flexible Validation Rules: Built-in rules like required, email, and customizable rules.
  • React Hook-based: Utilizes React's useState hook for managing form input and error states.
  • TypeScript Support: Full TypeScript support for type safety and developer experience.
  • Easy to Use: Simple API for quick integration into React forms.

📦 Installation

To install the library, run the following command:

npm install @lahiru.dev/check-mate

Or if you are using yarn:

yarn add @lahiru.dev/check-mate

⚡ Usage

1. Import the necessary hooks and validators:

import { useValidation } from "@lahiru.dev/check-mate";
import { isRequired, isEmail } from "@lahiru.dev/check-mate/validators";

2. Use the useValidation hook to handle form validation:

function EmailInput() {
  const { value, error, handleChange } = useValidation("", [isRequired, isEmail]);

  return (
    <div>
      <input
        type="email"
        value={value}
        onChange={handleChange}
        placeholder="Enter your email"
      />
      {error && <span style={{ color: "red" }}>{error}</span>}
    </div>
  );
}

3. Full Example: Using Multiple Fields in a Form

import React, { useState } from "react";
import { useValidation } from "@lahiru.dev/check-mate";
import { isRequired, isEmail } from "@lahiru.dev/check-mate/validators";

function SignUpForm() {
  const [isSubmitted, setIsSubmitted] = useState(false);
  
  const { value: email, error: emailError, handleChange: handleEmailChange } = useValidation("", [isRequired, isEmail]);
  const { value: name, error: nameError, handleChange: handleNameChange } = useValidation("", [isRequired]);

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    if (!emailError && !nameError) {
      setIsSubmitted(true);
    }
  };

  return (
    <form onSubmit={handleSubmit}>
      <div>
        <label htmlFor="email">Email:</label>
        <input
          type="email"
          id="email"
          value={email}
          onChange={handleEmailChange}
        />
        {emailError && <span style={{ color: "red" }}>{emailError}</span>}
      </div>

      <div>
        <label htmlFor="name">Name:</label>
        <input
          type="text"
          id="name"
          value={name}
          onChange={handleNameChange}
        />
        {nameError && <span style={{ color: "red" }}>{nameError}</span>}
      </div>

      <button type="submit">Submit</button>

      {isSubmitted && <p>Form submitted successfully!</p>}
    </form>
  );
}

export default SignUpForm;

🧑‍💻 API

useValidation(initialValue: string, rules: ValidationRule[])

A custom React hook that handles the form field value, validation, and error message.

Arguments:

  • initialValue (string): The initial value of the form field.
  • rules (ValidationRule[]): An array of validation rules to be applied to the field.

Returns:

  • value (string): The current value of the form field.
  • error (string | null): The error message if validation fails, or null if validation is successful.
  • handleChange (function): A handler function to update the form field value and trigger validation.

Validation Rules

  • isRequired(value: string): string | null
    Returns an error message if the field is empty, otherwise returns null.

  • isEmail(value: string): string | null
    Returns an error message if the value is not a valid email address, otherwise returns null.

Example:

const isRequired: ValidationRule = (value) => {
  return value.trim() ? null : "This field is required.";
};

const isEmail: ValidationRule = (value) => {
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) ? null : "Invalid email address.";
};

🎉 Thank you for using the library! 🎉


This README.md covers everything needed to introduce your library to developers and help them integrate it into their applications quickly.

Would you like to add more details like advanced configurations, API examples, or error handling in your documentation? Let me know!