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

rerevalidator

v1.3.1

Published

Handy wrapper around revalidator (https://github.com/flatiron/revalidator) and simple server method

Downloads

5

Readme

rerevalidator

Handy wrapper around revalidator and simple validation schemas serve method (more not needed to put revalidator and validation schemas in ./public).

It also performs data types conversions (for example, if you specified some field as 'integer' in your schema and pass object with string '123' in it, after validation passed object will contain number '123' instead of string in that field). It works with arrays too.

You can install rerevalidator through npm:

npm install rerevalidator

You should feel free to improve that documentation (so for sources) and suggest me a pull request.

wrapper

You can access wrapper through:

require('rerevalidator').validator;

This object has fields:

  • filters - is an object, which stores entity filters in format: {entityName{string}: revalidatorSchema{object}};
  • validate(entity, entry) - function, which performs validation of entry object with specified schema (entity may be schema name, early specified in filters or schema object), returns result of standard revalidator's validate() call;
  • types – object, which stores types constructors in format: {typeName{string}: typeConstructor{function}};
  • types.add(name, description) - method, which adds new types, name should be string, description may be object (in revalidator format) or function (type constructor); if you pass an object to this function, new construct will accept only two optional arguments: opt_required{boolean} and opt_conform{Function}.

default types

/**
 * @param {number|undefined} minimum
 * @param {number|undefined} maximum
 * @param {boolean=} opt_required
 * @param {Function=} opt_conform
 */
types.Integer(minimum, maximum, opt_required, opt_conform);

/**
 * @param {number|undefined} minimum
 * @param {number|undefined} maximum
 * @param {boolean=} opt_required
 * @param {Function=} opt_conform
 */
types.Number(minimum, maximum, opt_required, opt_conform);

/**
 * @param {number|undefined} length
 * @param {boolean=} required
 * @param {Function=} conform
 */
types.String(length, opt_required, opt_conform);

/**
 * @param {Array} values
 * @param {boolean=} required
 * @param {Function=} conform
 */
types.Enum(values, opt_required, opt_conform);

types.Timestamp(opt_required, opt_conform);
types.Text(opt_required, opt_conform);
types.Boolean(opt_required, opt_conform);
types.Email(opt_required, opt_conform);
types.PhoneNumber(opt_required, opt_conform);
types.ObjectId(opt_required, opt_conform);
types.DBRef(opt_required, opt_conform);
types.Lat(opt_required, opt_conform);
types.Lon(opt_required, opt_conform);
types.Point(opt_required, opt_conform);
types.GeoPointCoordinate(opt_required, opt_conform);
types.GeoPoint(opt_required, opt_conform);

server

If you needed to use same rerevalidator schemes on client you may simply serve rerevalidator and schemes to client by calling:

require('rerevalidator').serve(pathToSchemesScript, server);

After, it may be accessed via '/rerevalidator/minified.js' url.

You should manually implement check, where you schemes script is executed (in browser or by node), you may do this by calling typeof(window) – look in revalidator or rerevalidator sources for example.

In browser you can access rerevalidator as Validator object.

Server is any node.js http server.

After you should manually call server.listen to start it.

For more detailed documentation use sources.