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

validators

v0.3.1

Published

Validators for browsers and Node.js

Downloads

2,221

Readme

========================== Validators |travis_status|

.. |travis_status| image:: https://secure.travis-ci.org/insin/validators.png :target: http://travis-ci.org/insin/validators

Validators which can be shared between browsers and Node.js, based on Django's core validators.

Validators are Functions which take a value and throw a ValidationError if they detect that it is invalid.

Browsers:

  • validators.js_ / validators.min.js_

Node.js::

npm install validators

.. _Node.js: http://nodejs.org/ .. _Django: https://www.djangoproject.com/ .. _validators.js: https://raw.github.com/insin/validators/master/validators.js .. _validators.min.js: https://raw.github.com/insin/validators/master/validators.min.js

Error

ValidationError(messages[, {code: null, params: null}])

Validation error constructor.

For customisation purposes, in addition to a validation message, a ValidationError may specify a code to itentify the category of error and any params which were inserted into the validation message, when applicable.

For messages, you can pass:

  • a single message as a String
  • a list of messages
  • an object containing field-specific messages, with properties corresponding to field names.

Utilities

EMPTY_VALUES

Defines input values for which a field is considered to be empty. These are:

  • null
  • undefined
  • ''

Validators

RegexValidator(options)

Creates a validator which validates that input matches a regular expression.

Options which can be passed are:

  • regex -- the regular expression pattern to search for the provided value, or a pre-compiled RegExp. By default, matches any string (including an empty string)
  • message -- the error message used by ValidationError if validation fails. Defaults to "Enter a valid value".
  • code -- the error code used by ValidationError if validation fails. Defaults to "invalid".
  • inverseMatch -- the match mode for regex. Defaults to false.

URLValidator(options)

Creates a validator which validates that input looks like a valid URL.

Options which can be passed are:

  • schemes -- allowed URL schemes. Defaults to ['http', 'https', 'ftp', 'ftps'].

EmailValidator(options)

Creates a validator which validates that input looks like a valid e-mail address.

Options which can be passed are:

  • message -- error message to be used in any generated ValidationError.
  • code -- error code to be used in any generated ValidationError.
  • whitelist -- a whitelist of domains which are allowed to be the only thing to the right of the @ in a valid email address -- defaults to ['localhost'].

validateEmail(value)

Validates that input looks like a valid e-mail address -- this is a preconfigured instance of an EmailValidator,

validateSlug(value)

Validates that input is a valid slug.

validateIPv4Address(value)

Validates that input is a valid IPv4 address.

validateIPv6Address(value)

Validates that input is a valid IPv6 address.

validateIPv46Address(value)

Validates that input is a valid IPv4 or IPv6 address.

ipAddressValidators(protocol[, unpackIPv4])

Returns the appropriate validator for validating IPv4 or IPv6 addresses, passing 'ipv4', 'ipv6', or 'both' as protocol.

If a truthy unpackIPv4 argument is given and protocol is not 'both', an Error will be thrown.

validateCommaSeparatedIntegerList(value)

Validates that input is a comma-separated list of integers.

BaseValidator(limitValue)

Base constructor for validators which compare input against a given value.

MaxValueValidator(limitValue)

Validates that input is less than or equal to a given value.

MinValueValidator(limitValue)

Validates that input is greater than or equal to a given value.

MaxLengthValidator(limitValue)

Validates that input is at least a given length.

MinLengthValidator(limitValue)

Validates that input is at most a given length.

Additional IPv6 Functions

ipv6.isValidIPv6Address(value)

Returns true if input is a valid IPv6 address, false otherwise.

ipv6.cleanIPv6Address(value[, {errorMessage: '...', unpackIPv4: false}])

Cleans an IPv6 address string -- replaces the longest continious zero-sequence with '::' and removes leading zeroes and makes sure all hextets are lowercase.

If an invalid address is passed, a ValidationError is thrown.

MIT License

Copyright (c) 2014, Jonathan Buchanan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.