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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@andresclua/validate

v0.0.5

Published

A lightweight JavaScript utility for validating form fields like email and username. This example demonstrates how to integrate and use the library to ensure inputs meet specified criteria.

Downloads

293

Readme

Form Validation Library

A lightweight JavaScript utility for validating form fields like email and username. This example demonstrates how to integrate and use the library to ensure inputs meet specified criteria.

Why Choose This Library?

This validation library is designed with flexibility, modularity, and ease of use in mind. Here are the key reasons why it stands out:

Framework-Agnostic

This library is framework-agnostic, meaning it works seamlessly with any JavaScript environment:

  • Use it in plain JavaScript for lightweight projects.
  • Integrate it into frameworks like React, Vue, Svelte, or Angular.
  • Ideal for modern frontends or traditional setups.
  • Focused purely on validation; DOM manipulation or custom message handling is left to developers.
  • Includes built-in debugging tools to log detailed validation steps for easier troubleshooting.
  • Supports real-time validation (e.g., on blur, input, or change events).
  • Written in pure JavaScript with no dependencies, ensuring fast performance.
  • Ready for use in ES Modules, CommonJS, or browser environments.

Modular Design

Each validation function is a self-contained module, allowing you to:

  • Import only the functions you need, keeping your project lightweight.
  • Extend or modify specific validations without affecting others.
  • Scale effortlessly by adding new validators.
import { isEmail } from "@andresclua/validate";
import { isString } from "@andresclua/validate";

Customizable

The library allows extensive customization to suit your project requirements:

  • Define your own error messages with customMessage.
  • Configure validations for specific needs like corporate emails or pattern-based rules.
isEmail({
    element: "[email protected]",
    config: {
        type: "corporate",
        customMessage: "Please use a corporate email address.",
    },
});

Flexible Validation Flow

The library supports multiple ways to handle validation:

  • On blur: Validate inputs as the user interacts with them.
  • On submit: Validate all inputs when the form is submitted.
  • Combined flow: Use both for a robust user experience.
document.querySelector("#email").addEventListener("blur", () => {
    const result = isEmail({ element: emailInput.value });
    if (!result.isValid) {
        console.error(result.errorMessage);
    }
});

Examples

  • Validate Email Learn how to validate email addresses with various rules and customizations.

  • Validate Number Explore number validation, including range, positivity, and custom rules.

  • Validate String Explore String Validation, with configurable rules such as length, pattern matching.

  • Validate Checkbox Explore checkbox Validation, with configurable rules such as required, pattern matching,etc.

  • Select, Checkbox and Radio comming soon