Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nikitakozlovjr/validator
https://github.com/nikitakozlovjr/validator
Last synced: about 19 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/nikitakozlovjr/validator
- Owner: nikitakozlovjr
- Created: 2023-10-30T13:53:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-27T19:45:21.000Z (11 months ago)
- Last Synced: 2023-12-28T21:02:18.947Z (11 months ago)
- Language: JavaScript
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Maintainability](https://api.codeclimate.com/v1/badges/984748ab82fd2ed42032/maintainability)](https://codeclimate.com/github/nikitakozlovjr/Validator/maintainability)
## Validator
### Description
_____This module is designed for validating values. This validator provides validation functions:
- `number()`
- `string()`
- `array()`
- `function()`
- `object()`#### Validation of numbers
```javascript
const validator = new Validator();
const schemaNumber = validator.number()const isNumber1 = schemaNumber.isValid('4'); // false
const isNumber2 = schemaNumber.isValid(4); // true
```
____The number validator provides functions:
- `even()`
- `odd()`
- `interval()`##### Even method
___This method checks for the even number passed. If the passed value is a number and it is even, the method returns `true`, otherwise `false`
```javascript
const isEven1 = schemaNumber.even().isValid(4); // true
const isEven2 = schemaNumber.even().isValid(3); // false
const isEven3 = schemaNumber.even().isValid({ number: 4 }); // false
```##### Odd method
___This method checks for the odd number passed. If the passed value is a number and it is odd, the method returns true, otherwise false
```javascript
const isOdd1 = schemaNumber.odd().isValid(4); // false
const isOdd2 = schemaNumber.odd().isValid(3); // true
const isOdd2 = schemaNumber.odd().isValid({ number: 4 }); // false
```##### Interval method
___This method accepts two arguments as input:
- *min* -> number
- *max* -> number
It checks whether the transmitted number is in the range from min to max. If the passed value is a number and is included in the interval, the
method returns `true`, otherwise `false`.```javascript
const inInterval1 = schemaNumber.interval(1, 7).isValid(4); // true
const inInterval2 = schemaNumber.interval(4, 9).isValid(3); // true
const inInterval3 = schemaNumber.interval(3, 5).isValid({ number: 4 }); // false
```