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

valid-utils

v1.0.1

Published

A simple and flexible validation package for common data types and formats, including email, URLs, dates, numbers, and more.

Downloads

10

Readme

Welcome to Valid Utils

A simple and flexible validation package for common data types and formats, including email, URLs, dates, numbers, and more.

Installation

npm install valid-utils

Usage

import React, { useState } from "react";

// Assuming `isItValidPass` is imported from your utility file
import { isItValidPass } from "valid-utils";

const PasswordValidator: React.FC = () => {
  const [password, setPassword] = useState<string>("");
  const [validationResult, setValidationResult] = useState<string | null>(null);

  const validatePassword = () => {
    const options = {
      minLength: 8,
    };

    const { result, isValid } = isItValidPass(password, options);

    if (isValid) {
      setValidationResult("Password is valid");
    } else {
      setValidationResult(`Password is invalid: ${result}`);
    }
  };

  return (
    <div>
      <input
        type="password"
        value={password}
        onChange={(e) => setPassword(e.target.value)}
        placeholder="Enter your password"
      />
      <button onClick={validatePassword}>Validate Password</button>
      {validationResult && <p>{validationResult}</p>}
    </div>
  );
};

export default PasswordValidator;

Available Validation Functions

isItValidEmail

Validates an email address based on various customizable options.

  • Parameters:
    • email (string): The email address to validate.
    • options (optional EmailOptions): Optional configuration for the validation process.
  • Returns: { isValid: boolean, result: string }

isItValidPass

Validates a password based on various customizable options.

  • Parameters:
    • password (string): The password to validate.
    • options (optional PasswordOptions): Optional configuration for the validation process.
  • Returns: { isValid: boolean, result: string }

isItValidDate

Validates a date based on a specified format.

  • Parameters:
    • date (string): The date to validate.
    • format (string): The date format to validate (e.g., "YYYY-MM-DD", "MM/DD/YYYY", "DD/MM/YYYY").
  • Returns: { isValid: boolean, result: string }

isItValidNumber

Validates a numeric input based on various customizable options.

  • Parameters:
    • value (number | string): The number to validate.
    • options (optional NumericOptions): Optional configuration for the validation process.
  • Returns: { isValid: boolean, result: string }

isItValidUrl

Validates a URL based on various customizable options.

  • Parameters:
    • url (string): The URL to validate.
    • options (optional UrlOptions): Optional configuration for the validation process.
  • Returns: { isValid: boolean, result: string }

Type Definitions

ResponseShape

The shape of the response returned by validation functions.

| Property | Type | Description | |----------|---------------------|--------------------------------------------------| | isValid| boolean | Indicates whether the input is valid or not. | | result | string | number | The result of the validation. Contains validation errors or the valid input. |

GlobalOptions

Global options that apply to various validation functions.

| Property | Type | Description | | ----------- | -------- | ------------------------------------------ | | minLength | number | Minimum length for the input. | | maxLength | number | Maximum length for the input. | | pattern | RegExp | Regular expression pattern for validation. |

EmailOptions

Options specific to email validation.

| Property | Type | Description | | ------------------------ | ---------- | ------------------------------------------- | | allowSpecialCharacters | boolean | Allow special characters in the local part. | | allowedDomains | string[] | List of allowed domains. | | disallowedDomains | string[] | List of disallowed domains. | | caseSensitive | boolean | Case sensitivity for email validation. | | allowSubdomains | boolean | Allow subdomains in the domain part. | | requiredTLD | boolean | Require a top-level domain. | | isRequired | boolean | Whether the email is required. |

PasswordOptions

Options specific to password validation.

| Property | Type | Description | | --------------------- | -------- | ------------------------------------------------ | | requireUppercase | number | Minimum number of uppercase characters required. | | requireLowercase | number | Minimum number of lowercase characters required. | | requireNumbers | number | Minimum number of numeric characters required. | | requireSpecialChars | number | Minimum number of special characters required. | | specialChars | string | Allowed special characters. | | minUniqueChars | number | Minimum number of unique characters required. |

NumericOptions

Options specific to numeric validation.

| Property | Type | Description | | --------------- | -------- | --------------------------------- | | min | number | Minimum value allowed. | | max | number | Maximum value allowed. | | decimalPlaces | number | Number of decimal places allowed. |

UrlOptions

Options specific to URL validation.

| Property | Type | Description | | ----------- | -------------------- | ----------------------------------------- | | protocols | AllowedProtocols[] | Allowed URL protocols. | | format | RegExp | Regular expression format for validation. |

AllowedProtocols

This type defines the allowed protocols for URLs.

| Protocol | Description | | -------- | ---------------------------------- | | http | Hypertext Transfer Protocol | | https | Hypertext Transfer Protocol Secure | | ftp | File Transfer Protocol | | ftps | File Transfer Protocol Secure | | mailto | Email address | | file | Local file | | data | Data URL scheme | | tel | Telephone number | | sms | Short Message Service | | ws | WebSocket protocol | | wss | WebSocket Secure protocol |

Contributing

There are many different ways to contribute to React Router's development. If you're interested, check out our contributing guidelines to learn how you can get involved.