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

ease-validator

v1.10.18

Published

A custom React hook for form validation

Downloads

8

Readme

useSmartForm

🚀 A lightweight and powerful React Hook for handling forms with validation, file uploads, checkboxes, and more!

🌟 Features

  • Instant & On-Submit Validation – Real-time field validation with error messages.
  • Debounce Validation – Prevents excessive validation calls while typing.
  • 📂 File Upload Handling – Supports file size & type restrictions.
  • 🔄 Form Reset with Default Values – Reset form easily while keeping initial values.
  • 🔧 Optimized Performance with useReducer – Efficient state management.
  • 🎯 Supports All Input Types – Works with text, email, password, checkbox, file, etc.

📦 Installation

npm install ease-validator@latest 

or

yarn add ease-validator@latest 

🚀 Usage Example

import React from "react";
import useSmartForm from "ease-validator";

const validationSchema = {
  name: { required: true, minLength: 3, errorMessage: { required: "Name is required!", minLength: "Name is too short!" } },
  email: { required: true, pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, errorMessage: { required: "Email is required!", pattern: "Invalid email format!" } },
  password: { required: true, minLength: 6, errorMessage: { required: "Password required!", minLength: "Password too short!" } },
  file: { required: true, maxSize: 2 * 1024 * 1024, allowedTypes: ["image/png", "image/jpeg"] },
  terms: { required: true, type: "checkbox" },
};

const MyForm = () => {
  const { register, handleSubmit, errors, resetForm, isSubmitting } = useSmartForm(validationSchema);

  const onSubmit = (data) => {
    console.log("Form Submitted:", data);
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register("name")} placeholder="Name" />
      {errors.name && <p>{errors.name}</p>}

      <input {...register("email")} placeholder="Email" />
      {errors.email && <p>{errors.email}</p>}

      <input {...register("password")} type="password" placeholder="Password" />
      {errors.password && <p>{errors.password}</p>}

      <input {...register("file")} type="file" />
      {errors.file && <p>{errors.file}</p>}

      <input {...register("terms")} type="checkbox" /> Accept Terms
      {errors.terms && <p>{errors.terms}</p>}

      <button type="submit" disabled={isSubmitting}>Submit</button>
      <button type="button" onClick={resetForm}>Reset</button>
    </form>
  );
};

export default MyForm;

📖 API Reference

useSmartForm(validationSchema, initialValues)

Creates a form handler with validation and state management.

Parameters:

| Parameter | Type | Description | | ------------------ | ----------------- | ---------------------------------------- | | validationSchema | Object | Defines validation rules for each field. | | initialValues | Object (optional) | Default values for the form fields. |


register(name)

Returns input properties for controlled inputs.

Example:

<input {...register("email")} type="email" placeholder="Enter email" />

handleSubmit(callback)

Handles form submission.

Example:

<form onSubmit={handleSubmit((data) => console.log(data))}>
  <button type="submit">Submit</button>
</form>

resetForm()

Resets the form to its initial state.

Example:

<button type="button" onClick={resetForm}>Reset Form</button>

isSubmitting

Returns true if the form is being submitted.

Example:

<button type="submit" disabled={isSubmitting}>Submit</button>

📜 Validation Rules

You can pass validation rules as an object with these properties:

| Rule | Type | Description | | -------------- | ------- | -------------------------------------- | | required | Boolean | Marks the field as required. | | minLength | Number | Minimum number of characters required. | | pattern | RegExp | Regular expression for validation. | | maxSize | Number | Maximum file size (for file inputs). | | allowedTypes | Array | Allowed file MIME types. | | errorMessage | Object | Custom error messages. |


⭐ Why useSmartForm?

Easy to Use – No complex setup needed. ✔ Performance Optimized – Uses useReducer for better state handling. ✔ Customizable – Allows custom validation messages. ✔ Supports All Input Types – Works with text, email, password, file, checkbox, etc. ✔ Lightweight – Minimal bundle size.


📄 License

MIT License