https://github.com/stetsd/univalid-strategy-default
Default strategy implementation for univalid module (extends 'univalid-strategy')
https://github.com/stetsd/univalid-strategy-default
univalid univalid-strategy univalid-strategy-default validation
Last synced: 6 months ago
JSON representation
Default strategy implementation for univalid module (extends 'univalid-strategy')
- Host: GitHub
- URL: https://github.com/stetsd/univalid-strategy-default
- Owner: stetsd
- Created: 2018-03-01T05:32:55.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-04T03:40:51.000Z (about 8 years ago)
- Last Synced: 2025-10-16T09:44:31.852Z (9 months ago)
- Topics: univalid, univalid-strategy, univalid-strategy-default, validation
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# univalid-strategy-default
Default strategy for [univalid](https://github.com/StetsD/univalid) module.
Extends [univalid-strategy](https://github.com/StetsD/univalid-strategy) class
## Install
```sh
npm i univalid-strategy-default
```
## Usage
```js
const UnivalidStrategyDefault = require('univalid-strategy-default');
const usd = new UnivalidStrategyDefault();
```
## API
### applyFilter(filter, val)
Tests the pattern matching of symbols (by event)
**filter** - Type `string`
In current moment available patterns:
* oL - only latin symbols
* oC - only cyrillic symbols
* oN - only numbers
* oP - only numbers and latin symbols
**val** - Type `string`
### check(pack, core)
Validating the pack
**pack** - Type `object`
Structure of pack must be strict. Like that:
name, val, type - required fields
```js
//name, val, type - required fields
[
{
name: 'username',
val: 'Uriy',
type: 'required',
filter: 'oL',
msg: {
empty: 'You shall not pass',
invalid: 'Validation error',
filter: 'Filter error',
success: 'All right'
}
},
{
name: 'email',
val: 'Uriy@mzf.com',
type: 'email',
filter: /[a-z]|\s/gi,
msg: {
empty: 'You shall not pass',
invalid: 'Bad email',
filter: 'Only lat/numbers/specials symbols',
success: 'All right'
}
},
]
```
**core** - Type `object`
The instance of 'univalid' module
### getValidationHandlers()
Get validation handlers.
By default defined in [univalid-strategy](https://github.com/StetsD/univalid-strategy) abstract class
### set(option, val)
Set the option in instance
**option** - Type `string`
```js
usd.set('passConfig', {min: 10, analysis: ['hasLowercase', 'hasDigits', 'hasSpecials']});
```
## OPTIONS
### passConfig
Password config
**By default**
{min: 6, analysis: ['hasUppercase', 'hasLowercase', 'hasDigits', 'hasSpecials']}
```js
const usd = new UnivalidStrategyDefault({
passConfig: {min: 10, analysis: ['hasLowercase', 'hasDigits', 'hasSpecials']}
});
```
## License
ISC©