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

zn-verify

v1.2.2

Published

An NPM Package to verify user details

Readme

Here's the updated README.md file with the newly added validateAgeRange function:


Validation Utilities

A simple JavaScript/TypeScript library that provides utility functions for validating names, emails, phone numbers, calculating age, and validating age ranges. This library is designed to simplify common validation tasks in your projects.

Features

  • Validate names to ensure they contain only letters and spaces.
  • Validate emails for general purposes or specific domains.
  • Validate Indian mobile numbers, including support for +91 and 0 prefixes.
  • Calculate age from a date in different formats (e.g., dd/mm/yyyy, dd-mm-yyyy, or a Date object).
  • Validate if an age falls within a specified range.

Installation

To use this library, install it via npm or yarn:

npm install zn-verify

or

yarn add zn-verify

Functions

1. verifyName

Validates a name to ensure it contains only letters and spaces, with no consecutive spaces or digits.

Usage

import { verifyName } from "zn-verify";

console.log(verifyName("John Doe")); // true
console.log(verifyName("John  Doe")); // false
console.log(verifyName("John123")); // false

Rules:

  • No consecutive spaces.
  • Cannot start or end with a space.
  • No digits are allowed.

2. verifyEmail

Validates an email address for general use or against a specific domain.

Usage

import { verifyEmail } from "zn-verify";

console.log(verifyEmail("[email protected]")); // true
console.log(verifyEmail("[email protected]", "gmail.com")); // true
console.log(verifyEmail("[email protected]", "gmail.com")); // false

Parameters

  • email (string): The email address to validate.
  • specialDomain (string, optional): A specific domain to validate against (e.g., gmail.com).

Behavior

  • If specialDomain is provided, the email must match that domain.
  • Otherwise, it validates the email format against a general-purpose regex.

3. verifyMobileNumber

Validates an Indian mobile number, supporting prefixes like +91 and 0.

Usage

import { verifyMobileNumber } from "zn-verify";

console.log(verifyMobileNumber("+919876543210")); // true
console.log(verifyMobileNumber("09876543210")); // true
console.log(verifyMobileNumber("9876543210")); // true
console.log(verifyMobileNumber("1234567890")); // false

Rules

  • Mobile numbers must start with digits 6-9.
  • Can optionally have +91 or 0 as a prefix.
  • Must contain exactly 10 digits (excluding the prefix).

4. calculateAge

Calculates the age based on a provided date. The date can be in dd/mm/yyyy, dd-mm-yyyy, or a Date object.

Usage

import { calculateAge } from "zn-verify";

console.log(calculateAge("01/01/2023")); // "12 months" (if today is 01/01/2024)
console.log(calculateAge("31-12-2023")); // "1 day" (if today is 01/01/2024)
console.log(calculateAge(new Date(2000, 0, 1))); // "24 years" (if today is 01/01/2024)

Parameters

  • dateInput (string | Date): The input date to calculate age from.

Output

  • Returns the age in one of the following formats:
    • X days (if less than 30 days).
    • X months (if less than 12 months).
    • X years (if 1 year or more).

5. validateAgeRange

Validates if an age calculated from a date falls within a specified range.

Usage

import { validateAgeRange } from "zn-verify";

// No age range specified (validates all ages)
console.log(validateAgeRange("01/01/2000")); // true

// Only maxAge specified
console.log(validateAgeRange("01/01/2010", undefined, 20)); // true (if age <= 20)

// Only minAge specified
console.log(validateAgeRange("01/01/2005", 18)); // true (if age >= 18)

// Both minAge and maxAge specified
console.log(validateAgeRange("01/01/1990", 18, 30)); // false (if age is outside 18-30)

Parameters

  • dateInput (string | Date): The input date to validate.
  • minAge (number, optional): The minimum age (defaults to 0).
  • maxAge (number, optional): The maximum age (defaults to Infinity).

Output

  • Returns true if the age falls within the specified range.
  • Returns false otherwise.

Behavior

  • Throws an error if the date is invalid or in the future.
  • Defaults minAge to 0 and maxAge to Infinity if not specified.

Error Handling

All functions throw an error for invalid input formats. Ensure inputs follow the documented formats.

Contribution

Contributions are welcome! Please submit a pull request or open an issue on the GitHub repository.

License

This library is licensed under the MIT License.


Changelog

v1.2.1 (Patch Update)

  • Breaking Change: Functions no longer return a promise. They are now synchronous for easier usage.
  • Added validateAgeRange to validate if an age is within a specified range.
  • Updated documentation to reflect the changes.

v1.2.0

  • Added verifyName function for name validation.
  • Enhanced verifyEmail function to support specific domain validation.
  • Added verifyMobileNumber function to validate Indian mobile numbers.
  • Improved calculateAge function to handle multiple date formats.

v1.0.0

  • Initial release with basic validation functionality.

Let me know if further adjustments are needed!