# esc-validation

> Validation solution

Latest version **1.0.12** (published 2023-01-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install esc-validation
pnpm add esc-validation
yarn add esc-validation
bun add esc-validation
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2023-01-23 |
| First published | 2022-11-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 33.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ali Iybar |
| Maintainers | aliiybar |
| Keywords | validation |

## Links

- npm: https://www.npmjs.com/package/esc-validation
- npm.io page: https://npm.io/package/esc-validation

## Dependencies (1)

- [moment](https://npm.io/package/moment.md) ^2.29.4

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.12 (latest) — 2023-01-23
- 1.0.11 — 2023-01-22
- 1.0.10 — 2023-01-18
- 1.0.8 — 2023-01-07
- 1.0.7 — 2023-01-07
- 1.0.5 — 2023-01-06
- 1.0.4 — 2022-11-21
- 1.0.3 — 2022-11-21
- 1.0.2 — 2022-11-21
- 1.0.1 — 2022-11-04
- 1.0.0 — 2022-11-02

## README

# Validation Library
## FormStructure

* __name__ : <font color="green">_string_</font> name of the field
* __id__ : <font color="green">_string_</font> [optional]  if it's not provided name is used for id 
* __value__ : value of the field
* __label__ : label of the field
* __type__ : type of the field. it can be of them :
    * __text__ : 
    * __number__:
    * __date__:
* __validations__: <font color="green">_array_</font> validations as array which contains 
    * __type__ : validation type (See validation types)
    * __text__ : validation message 
    * __value__ : validation rule depending on the validation type 
* __isVisited__ : <font color="green">_boolean_</font> indicated if a field is visited or not. If you merge data this field will be automatically added
* __isDirty__ : <font color="green">_boolean_</font> indicated if a field is visited or not. If you merge data this field will be automatically added
* __isValid__ : <font color="green">_boolean_</font> indicated if a field is visited or not. If you merge data this field will be automatically added
* __messages__ : <font color="green">_array_</font> string array

## Validation Rules
### Structure
* __type__ : Validation rule type. See below list for different types
* __text__ : Validation message. This message will be sent if field doesn't match the validation criteria
* __value__: Validation rule criteria / details. It can be various different strings depending on the validation type 
### Rules
#### type : required
It checks if any value is entered to the field and invalid. No __value__ is needed for this rule
#### type : min
This rule acts different based on form field type.
* if the field data type is __date__ : rule value can be in two different format 
    * fix __YYYY-MM-DD__ format. In this case minimum field value must be later than this date
    * variable __Number,Unit,before/after__ format. ie : __3,M,before__ means 3 month earlier than today is the minimum date otherwise it's invalid.
    
    Unit List :
    | Date | Unit |
    | ---- | ---- |
    | years | y |
    | quarters | Q |
    | months | M |
    | weeks	| w |
    | days | d |
    | hours | h |
    | minutes | m |
    | seconds | s |
    | milliseconds | ms |

## Sample validation object
```
const fields = [
        {
            name:"testName1",
            label:"Test Name",
            type:"text",
            value:"12",
            isVisited:true,
            validations:[
                {
                type:"min",
                value:"3",
                text:"min 3"
                }
            ]
        },
        {
            name:"testName2",
            label:"Test Name",
            type:"text",
            value:"123456",
            isVisited:true,
            validations:[
                {
                    type:"pattern",
                    value:"123ab",
                    text:"pattern"
                },
                {
                    type:"max",
                    value:"5",
                    text:"max 5"
                },
                {
                    type:"cross-same",
                    value:"testName1",
                    text:"cross"
                }
            ]
        },
        {
            name:"testName3",
            label:"Test Name 3",
            type:"text",
            value:"1245",
            isVisited:true,
            validations:[
                {
                type:"min",
                value:"3",
                text:"min 3"
                }
            ]
        },
    ]
```

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