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

input-vld

v0.5.1

Published

Package for inputs validation

Downloads

2

Readme

First version of my validator for checking inputs.
Now support form and separately: email, password and string length validation.

Changelog
v. 0.1.1 - Change file structure.
v. 0.2.0 - Add form validation.
v. 0.3.0 - Add dynamic creating validation rules
v. 0.3.1 - Add min-max validation for number in input
v. 0.4.0 - config generator v. 0.5.0 - upload to NPM
v. 0.5.1 - change import

In progress:
v. 0.6 - refactoring with TS

  • Change code to more declarative style
  • Adding new features

How to use.
Create folders 'helpers/validator' in your project directory.
Copy code (./src and index.js) from this repository to your folder 'validator'.
Import stringValidator or formValidator from ('/helpers/validator').

Create your configuration like example below, then use Generator for creating config. Example:

// config.js
const Generator = require('...../src/Generator.js');

const myRules = {
  password: {
    maxLength: { value: 7, msg: 'Max 7' },
    minLength: { value: 1 },
    upperCase: { value: 3, msg: 'Min 3' }
  },
  email: {
    email: { value: 1 },
    localLength: { value: 64, msg: '64 no more' },
    minLength: { value: 1 },
    maxLength: { value: 256, msg: 'Max 256' }
  },
  price: {
    min: { value: 7 },
    max: { value: 999 }
  }
};

module.exports = Generator(myRules);

Currently you can use this params for validation:
upperCase:int - Minimal amount of upper-case letters in string
lowCase: int - Minimal amount of low-case letters in string
numbers: int, - Minimal amount of numbers in string
min: int, Minimal value of input's number
max: int, Max value of input's number
minLength: int, Minimal length of string
maxLength: int, Max length of string
email: int, Is str should be email (1 it true, either 0 )
localLength: int, Max length of email local part

And than use function stringValidator or formValidator.

stringValidator receive arguments:
str == value for validation :: string,
config == object with validation rules:: object,
type == rule which will be used for validation:: string
and return array.
Array can be empty if it has not errors during validation, or contain objects:
{status: boolean, msg: string, params: string}
Status indicate error, message take error message from your config, and params equal to rule value which didn't pass validation.

FormValidator receive arguments
( form == form :: object, config == object with validation rules:: object )
Form must have this structure:
{ruleName1: 'str', ruleName2: 'str', ...}
ruleName is a name of form filed which MUST be named same as a validation rule for it.
formValidator() return an array with this structure:

[
  { data: [[Object]], key: 'ruleName1' },
  { data: [[Object]], key: 'ruleName2' }
];

where [Object] is the same as result for stringValidator()