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

validations-js

v1.0.1

Published

Simple DSL for performing simple validations.

Downloads

4

Readme

README

This document explains how to use the library.

Usage

First, you need to import the package into your code:

require('validations-js');

...

Then, follow these instructions for each function:

isEven(number)

Checks if a number is even.

Parameters:

  • number: int value.

Examples:

>> isEven(2)
>> true

>> isEven(1)
>> false

isOdd(number)

Checks if a number is odd.

Parameters:

  • number: int value.

Examples:

>> isOdd(2)
>> false

>> isOdd(1)
>> true

isPositive(number)

Checks if a number is positive or zero.

Parameters:

  • number: numeric value.

Examples:

>> isPositive(2)
>> true

>> isPositive(0.0)
>> true

>> isPositive(-3.1)
>> false

nonPositive(number)

Checks if a number is strictly negative

Parameters:

  • number: numeric value.

Examples:

>> nonPositive(2)
>> false

>> nonPositive(0.0)
>> false

>> nonPositive(-3.1)
>> true

isAlphabetic(string)

Checks if an string contains only letters.

Parameters:

  • string: string value.

Examples:

>> isAlphabetic("Hello world")
>> true

>> isAlphabetic("This w11l be f4ls3")
>> false

isAlphanumeric(string)

Checks if a string contains only letters and numbers.

Parameters:

  • string: string value.

Examples:

>> isAlphanumeric("Hello world")
>> true

>> isAlphanumeric("This w0n'7 be f4ls3")
>> true

>> isAlphanumeric("?????")
>> false

isNumeric(string)

Checks if a string contains only numbers.

Parameters:

  • string: string value.

Examples:

>> isNumeric("Hello world")
>> false

>> isNumeric("This w111 be f4ls3")
>> false

>> isNumeric("1234")
>> true

>> isNumeric("3.1415")
>> false

isValidPercentage(number)

Checks that a number that represents a percentage is within the proper bounds.

Parameters:

  • number: numeric value.

Examples:

>> isValidPercentage(2)
>> false

>> isValidPercentage(0.0)
>> true

>> isValidPercentage(1.)
>> true

>> isValidPercentage(50.0)
>> false

isValidTimestamp(date, unit):

Checks that a number that represents a date as milliseconds or seconds is correct.

Parameters:

  • date: int.

  • unit: String. 'millis' if date is in milliseconds, 'seconds' if date is in seconds.

Examples:

>> isValidTimestamp(2, "seconds")
>> false

>> isValidTimestamp(1234567890, "millis")
>> false

>> isValidTimestamp(1465496168, "seconds")
>> true

>> isValidTimestamp(1465496168000, unit="millis")
>> true

present(field_name, dictionary)

Checks if a field is present in an object.

Parameters:

  • field_name: string.

  • dictionary: object instance.

Examples:

dictionary = {'a': 1, 'b': 2}
>> present('c', dictionary)
>> false

>> present('a', dictionary)
>> true

isEmpty(iterable)

Checks if an iterable is empty

Parameters:

  • iterable: Iterable instance (an array or object).

Examples:

>> isEmpty([])
>> true

>> isEmpty([1,2,3])
>> false

>> isEmpty({'a': 1})
>> false

>> isEmpty({})
>> true

nonEmpty(iterable)

Checks if an iterable has at least one element.

Parameters:

  • iterable: Iterable instance (an array or object).

Examples:

>> nonEmpty([])
>> false

>> nonEmpty([1,2,3])
>> true

>> nonEmpty({'a': 1})
>> true

>> nonEmpty({})
>> false