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

matts-sick-validation-func

v0.8.1

Published

Validation functions

Readme

Matts Sick Validation Func

Probably the best validation utility ever made 😜

Installing

npm i --save matts-sick-validation-func

Usage

Import the main validate function

Using JS modules

import validate from 'matts-sick-validation-func';

OR using require e.g. Node JS

const validate = require('matts-sick-validation-func').default;

Getting started

Valid value example:

const result = validate
  .test('Test value')
  .isAlphabet({ message: 'Value is not a letter' })
  .hasLowerCase({ message: 'No lowercase' })
  .hasUpperCase({ message: 'No uppercase' })
  .errors();

result.join(', '); // Outputs ''

Invalid value example:

const result = validate
  .test('123')
  .isAlphabet({ message: 'Value is not a letter' })
  .hasLowerCase({ message: 'No lowercase' })
  .hasUpperCase({ message: 'No uppercase' })
  .errors();

result.join(', '); // Outputs 'Value is not a letter, No lowercase, No uppercase'

Overview

Main validation function

Test value is valid

validate.test('123').isNumeric().isValid; // true
validate.test('ABC').isNumeric().isValid; // false

You can also chain functions together

validate
  .test('Abc123')
  .hasUpperCase()
  .hasDigits().isValid; // true

Function parameters

You can pass an object to refine your validation requirements

  • value: Value to validate when using stand-alone functions ( not to be used when using main validate function or chaining )
  • regex: Regex pattern literal or string used to validate ( e.g. /^[a-z]$/ or '^[a-z]$' )
  • fn: Function that is used to validate ( value is automatically passed into function as parameter )
  • min: Minimum number characters that must match to be valid
  • max: Maximum number characters that must match to be valid
  • message: String that will be shown when validation does not meet requirements
  • isPriority: Boolean that will save the message to the priorityMessage property

Examples

isAlphabet({ value: 'ABC', min: 2, max: 3 }).isValid  // true
isAlphabet({ value: 'ABCD', min: 2, max: 3 }).isValid  // false
isAlphabet({ value: 'ABCD', min: 2, max: 3, message: 'Too long!' }).messages  // ['Too long!']

validate
  .test('test')
  .isNumeric({ message: 'Value is not a number' })
  .hasUpperCase({ message: 'Value does not have uppercase characters'})
  .messages  // ['Value is not a number', 'Value does not have uppercase characters']

validate
  .test('Abc 123')
  .matches({ fn: (val) => exampleDbQueryFunction(val).length > 0 })
  .isValid  // true

validate
  .test('123')
  .isAlphabet({ message:'Not letters', isPriority = true })
  .hasUpperCase({ message: 'No uppercase' })
  .priorityMessage // 'Not letters'

Stand-alone functions

You can import stand-alone functions too which can help tree-shaking

  • hasDigits
  • hasUpperCase
  • hasLowerCase
  • isAlphanumeric
  • isAlphabet
  • isNumeric
  • lengthBetween
import { isAlphabet, isNumeric } from 'matts-sick-validation-func';

isAlphabet({ value: 'ABC' }).isValid; // true
isAlphabet({ value: '123' }).isValid; // false
isNumeric({ value: '123' }).isValid; // true

If you wish to use a custom regex use the matches function:

validate.test('Abc 123').matches({ regex: /[a-zA-Z\s\d]/ }).isValid; // true

Reverse validation result with invert function - pass the function you wish to invert as first parameter then that functions arguments as the second - the example below shows reversing the matches example above:

validate.test('Abc 123').invert('matches', { regex: /[a-zA-Z\s\d]/ }).isValid; // false

Check for errors with errors function

Aside from getting the result of a validation directly using .isValid or .messages you can call .errors() which will retrieve either the priorityMessage and output as an array or the messages array. You can alternatively pass in a function which is passed the whole validation object as a parameter and will only execute if the value is invalid

In the example below isPriority is not passed into any validate methods and no funciton is passed into .errors() so the result will be the messages array:

validate
  .test('Abc 123')
  .isAlphabet({ message: 'Not all letters' })
  .invert('matches', { regex: /[a-zA-Z\s\d]/, message: 'Value is invalid' })
  .errors(); // ['Not all letters', 'Value is invalid']

In the example below a function is passed into .errors() and the function will be called if the value is invalid:

const doSomethingWithMessages = ({ messages }) => {
  console.log(messages);
};

validate
  .test('Abc 123')
  .invert('matches', { regex: /[a-zA-Z\s\d]/, message: 'Value is invalid' })
  .errors(doSomethingWithMessages); // logs messages array

Extend with your own functions

Import the base ValidateBase function and pass in an object with your custom named functions using the matches function

import { ValidateBase } from 'matts-sick-validation-func';

const customValidate = new ValidateBase({
  isWebAddress: ({ value, min = 0, max = '', message } = {}) =>
    customValidate.matches({
      value,
      regex: `^((https?):\/\/)?(www.)?[a-z0-9]+\.[a-z]+\.[a-z]+(\/[a-zA-Z0-9.#]+\/?){${min},${max}}$`,
      message,
      isPriority
    })
});