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

vava

v0.4.2

Published

NodeJS variable validator

Downloads

2

Readme

Variable Validator (vava)

Simple, clean and efficient variable validator for node.

NPM Version Build status

Example usage

Full syntax:

var Vava = require('vava');

function updateUserName(id, name)
{
    Vava.Check.Is(id, "id", Vava.Type.isInt);
    Vava.Check.Is(name, "name", Vava.Type.isString, Vava.String.isNotEmptyOrWhitespace);
    
    // Some code
}

Short syntax - methods from Check are imported to container

var Vava = require('vava');

function updateUserName(id, name)
{
    Vava.Is(id, "id", Vava.Type.isInt);
    Vava.Is(name, "name", Vava.Type.isString, Vava.String.isNotEmptyOrWhitespace);
    
    // Some code
}

Shortest syntax - container by itself is instance of Check.Is method

var Vava = require('vava');

function updateUserName(id, name)
{
    Vava(id, "id", Vava.Type.isInt);
    Vava(name, "name", Vava.Type.isString, Vava.String.isNotEmptyOrWhitespace);
    
    // Some code
}

Installation

$ npm install --save vava

Bundled assertions

All functions in bundled assertions returns null if provided variable satisfies function's validation logic or string with error message. This error message will be exception text when Check.Is invoked

Type

Base package with basic assertions rules

Type.isNull & Type.isNotNull

Type.isBoolean & Type.isBool & Type.isNotBoolean

Type.isNumber & Type.isNotNumber

Type.isInteger & Type.isNotInteger

Type.isFloat & Type.isNotFloat

Type.isFunction & Type.isNotFunction

Type.isArray & Type.isNotArray

Type.isNotEmptyArray

This function returs null (which means true) if argument is array with length 1 or greater

Type.equalsTo(expected)

Parametrized assertion, than returns null (which means true) only when validated value has same type and value with expected one.

Check(x, "x", Check.Type.equalsTo(500)); // Will throw exception on any value except (number) 500

Type.isOneOf(expected)

Parametrized assertion, than returns null (which means true) only when validated value presents in list of expected values

Check(x, "x", Check.Type.isOneOf(["Banana", "Orange"]));

Net

Package with assertion for network purposes

Net.isIp with alias Net.isIpv6

Returns null (which means true) if provided argument is valid IPv4 or IPv6 address

Net.isIpv4

Returns null (which means true) if provided argument is valid IPv4 address

Net.isMacAddress

Returns null (which means true) if provided argument is valid MAC address

String

Package with string-specific assertions

String.isEmpty & String.isNotEmpty

String.isNotEmptyOrWhitespace

Returns null (which means true) if provided argument is string and contains at least one non-whitespace character.

String.isHexadecimal

String.isJson

String.isAscii

Returns null (which means true) if provided argument is string with single-byte characters only. Empty string is not valid Ascii string

String.isAsciiOrEmpty

Same as String.isAscii, but empty string counts as valid

String.isMultibyte

Returns null (which means true) if provided argument is string with at least one multibyte character. Empty string is not valid multibyte string

String.isMultibyteOrEmpty

Same as String.isMultibyte, but empty string counts as valid

String.isUuid & String.isUuid3 & String.isUuid4 & String.isUuid5

Returns null (which means true) if provided argument is string and satisfies rules for UUID

String.withExactLength(length)

Parametrized function, which returns null only if provided value is string with expected length

Check(x, "x", String.withExactLength(3));

String.withLength(max[, min])

Parametrized function, which returns null only if provided value is string with expected length

Check(x, "x", String.withLength(3)); // Any string with length 0, 1, 2, 3 chars
Check(x, "x", String.withLength(3, 5)); // Any string with length 3, 4, 5 chars
Check(x, "x", String.withLength(5, 3)); // Any string with length 3, 4, 5 chars

CreditCard

Contains assertions for credit card validation. Works only on sanitized data, so remove spaces, dashes by yourself

Known major card vendors:

  • Visa - CreditCard.isVisa
  • American Express - CreditCard.isAmex
  • Mastercard - CreditCard.isMastercard
  • Maestro - CreditCard.isMaestro
  • JCB - CreditCard.isJcb
  • Discover - CreditCard.isDiscover

CreditCard.isCreditCard

Returns null (which means true) if provided argument is string and holds credit card number of known vendor

CreditCard.isLuhnValid

Returns null (which means true) if provided argument is string and holds credit card number of known vendor, plus credit card number passes Luhn validation

CreditCard.isBin

Returns null (which means true) if provided argument holds something similar to BIN

CreditCard.isLast4

Returns null (which means true) if provided argument holds something similar to last four digits of credit card