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

qa-smart-validator

v1.0.1

Published

Reusable validation library for QA automation testing

Readme

qa-smart-validator

A small, framework-agnostic validation library for QA automation. Use it in Node.js test scripts, CI checks, or any JavaScript environment (Node.js ≥ 18). No Playwright or test-runner dependency—just validators and a safe wrapper so your automation never crashes on bad input.

Features

  • Email validator – Standard format; supports gmail.com, outlook.com, yahoo.com, and custom domains (e.g. example.com). Rejects empty, null, and invalid formats.
  • String validator – Ensures value is a string and enforces optional min/max length (after trim). Clear, controlled errors.
  • Phone validator – Digits only; length 10–15. Rejects empty, null, non-digits, and out-of-range length.
  • safeValidate(fn) – Wraps any sync validation in try/catch. Returns { valid: true, data } or { valid: false, error } so execution never throws.
  • ValidationError – All validators throw this (subclass of Error) with message, code, and optional field for stable assertions and reporting.

Requirements

  • Node.js ≥ 18
  • ES Modules ("type": "module" or .mjs)

Installation

npm install qa-smart-validator

Usage

import {
  validateEmail,
  validateString,
  validatePhone,
  safeValidate,
  ValidationError,
} from 'qa-smart-validator';

Validator examples

validateEmail(email)

Supports gmail.com, outlook.com, yahoo.com, and custom domains (e.g. example.com). Rejects empty, null, and invalid formats.

validateEmail('[email protected]');       // { valid: true, message: 'Valid email' }
validateEmail('[email protected]');  // { valid: true, message: 'Valid email' }
validateEmail('');                     // throws ValidationError: Email cannot be empty
validateEmail(null);                   // throws ValidationError: Email is required
validateEmail('not-an-email');         // throws ValidationError: Invalid email format

validateString(value, minLength?, maxLength?)

Ensures value is a string and enforces optional min/max length (after trim).

validateString('hello', 1, 10);  // { valid: true, value: 'hello' }
validateString('short', 10);     // throws ValidationError: String length 5 is less than minimum 10
validateString(123);             // throws ValidationError: Value must be a string, got number

validatePhone(phone)

Digits only; length 10–15.

validatePhone('1234567890');   // { valid: true, value: '1234567890' }
validatePhone('+1234567890');  // throws ValidationError: Phone must contain only digits
validatePhone('123');          // throws ValidationError: Phone length 3 is less than minimum 10

safeValidate example

Wraps execution in try/catch and returns a structured result. Never throws.

  • Success: { valid: true, data }data is the return value of the function.
  • Failure: { valid: false, error }error is the thrown error message.
import { validateEmail, safeValidate } from 'qa-smart-validator';

const result = safeValidate(() => validateEmail('[email protected]'));

console.log(result);
// { valid: true, data: { valid: true, message: 'Valid email' } }

const failed = safeValidate(() => validateEmail(''));
console.log(failed);
// { valid: false, error: 'Email cannot be empty' }

Example file

An example.js is included in the package. After installing, you can run it from your app directory:

node example.js

API summary

| Export | Description | |-------------------|-------------| | validateEmail | Validates email; throws ValidationError on failure. | | validateString | Validates string and optional length; throws ValidationError on failure. | | validatePhone | Validates phone (digits, 10–15); throws ValidationError on failure. | | safeValidate(fn)| Runs fn() in try/catch; returns { valid, data } or { valid, error }. | | ValidationError | Error class with message, code, field. | | EMAIL_REGEX | RegExp for email (advanced use). | | DIGITS_ONLY | RegExp for digits (advanced use). | | PHONE_MIN_LENGTH / PHONE_MAX_LENGTH | 10 and 15 (advanced use). |

Contributing

  1. Fork the repository.
  2. Create a branch (git checkout -b feature/your-feature).
  3. Run tests: npm test. Run lint: npm run lint. Format: npm run format.
  4. Commit your changes and push the branch.
  5. Open a Pull Request.

Publishing to npm

Before publishing:

  1. Dry run – See what will be packed and run lint/tests:
    npm run prepublishOnly
    npm pack
  2. Login (if needed):
    npm login
  3. Publish (scoped packages use --access public for first publish):
    npm publish --access public

Update repository, bugs, homepage, and author in package.json to your own repo and identity before publishing.

License

MIT