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

tmt-form-validator

v1.0.2

Published

This is a simple form validation library for JavaScript/TypeScript to validate form fields. It provides common validators (required, minLength, maxLength, email, numeric, phone number, etc.) and allows easy integration into your forms.

Downloads

197

Readme

Simple Form Validation Library

This is a simple form validation library for JavaScript/TypeScript to validate form fields. It provides common validators (required, minLength, maxLength, email, numeric, phone number, etc.) and allows easy integration into your forms.

Features

  • Easy-to-use API for adding validation rules
  • Built-in common validation rules such as required, minLength, email, etc.
  • Ability to add custom validation rules
  • Provides error messages when validation fails

Installation

To install the library, run the following command in your project directory:

bash npm install tmt-form-validator

Usage Example:

Here's the code written using markdown formatting:

First, we import the necessary components:

import { FormValidator, Validators } from 'simple-form-validation-lib';

Then, we create a new form validator:

const formValidator = new FormValidator();

Add validation rules for the username field

formValidator.addFieldRules('username', [ Validators.required('Username is required'), Validators.minLength(3, 'Username must be at least 3 characters'), ]);

Add validation rules for the email field

formValidator.addFieldRules('email', [ Validators.required('Email is required'), Validators.email('Invalid email address'), ]);

Validate a form

const formValues = { username: 'John', email: '[email protected]', };

Validate the form values

const errors = formValidator.validateAll(formValues);

if (formValidator.isValid(errors)) { console.log('Form is valid!'); } else { console.log('Validation Errors:', errors); }

Available Validators

| Validator | Description |-----|----- | required(message) | Ensures the field is not empty | minLength(length, message) | Ensures the field has at least the specified length | maxLength(length, message) | Ensures the field does not exceed the specified length | email(message) | Ensures the field contains a valid email address | numeric(message) | Ensures the field is a valid number | phoneNumber(message) | Ensures the field contains a valid phone number (in E.164 format) | pattern(regex, message) | Ensures the field matches the specified regular expression pattern | equalTo(value, message) | Ensures the field value is equal to another value

Methods

| Method | Description |-----|----- | addFieldRules(field: string, rules: ValidationRule[]): void | Adds validation rules for a specific field | validateField(field: string, value: any): string[] | Validates a single field and returns an array of error messages | validateAll(values: Record<string, any>): Record<string, string[]> | Validates all fields in the form and returns a record of errors | isValid(errors: Record<string, string[]>): boolean | Checks if the form is valid (no errors)

License

This package is licensed under the MIT License.

Feel free to contribute to this project by submitting issues or pull requests on our GitHub repository.