# input-vld

> Package for inputs validation

Latest version **0.5.1** (published 2020-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install input-vld
pnpm add input-vld
yarn add input-vld
bun add input-vld
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2020-02-18 |
| First published | 2020-02-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dimas |
| Maintainers | potdmk |

## Links

- npm: https://www.npmjs.com/package/input-vld
- npm.io page: https://npm.io/package/input-vld

## Recent versions

- 0.5.1 (latest) — 2020-02-18
- 0.4.0 — 2020-02-18

## 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:

```js
// 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:

```js
[
  { data: [[Object]], key: 'ruleName1' },
  { data: [[Object]], key: 'ruleName2' }
];
```

where `[Object]` is the same as result for `stringValidator()`

---
_Source: https://npm.io/package/input-vld · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
