Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aminnairi/validator
JavaScript library to validate an object of values based on a set of given rules.
https://github.com/aminnairi/validator
javascript node nodejs rule rules validation validator
Last synced: about 5 hours ago
JSON representation
JavaScript library to validate an object of values based on a set of given rules.
- Host: GitHub
- URL: https://github.com/aminnairi/validator
- Owner: aminnairi
- License: mit
- Created: 2020-11-02T12:08:23.000Z (about 4 years ago)
- Default Branch: latest
- Last Pushed: 2020-11-18T19:35:28.000Z (almost 4 years ago)
- Last Synced: 2024-05-27T22:05:12.334Z (6 months ago)
- Topics: javascript, node, nodejs, rule, rules, validation, validator
- Language: JavaScript
- Homepage:
- Size: 124 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# validator
![Tests](https://github.com/aminnairi/validator/workflows/Tests/badge.svg?branch=latest) ![Code Style](https://github.com/aminnairi/validator/workflows/Code%20Style/badge.svg?branch=latest)
JavaScript library to validate an object of values based on a set of given rules.
*:warning: This library is still in its early stage. Usage is permitted but without any guarantees the API will not change in a near future.*
```javascript
"use strict";const {Validator} = require("@aminnairi/validator");
new Validator({secret: "required|string|password"}).validate({secret: "kitten123"});
```## Requirements
- [Git](https://git-scm.com/)
- [NPM](https://www.npmjs.com/)## Installation
```console
$ npm install aminnairi/validator
```## Uninstallation
```console
$ npm uninstall @aminnairi/validator
```## API
### Constructor
#### Synopsis
Instanciate a new validator.
#### Prototype
```typescript
new: (rules: Record) => Validator;
```### setTranslations
#### Synopsis
Customize the error messages generated by the validator.
#### Prototype
```typescript
setTranslations: (translations: Record>) => void;
```### validate
#### Synopsis
Return properties that do not match the rules set for the created validator.
#### Prototype
```typescript
validate: (data: Record) => null | Record;
```## Rules
### Date
#### Synopsis
Check if the value is a date.
#### Example
See [`example/date.js`](./examples/date.js).
### Different
#### Synopsis
Check if the value is not equal to another.
#### Example
See [`example/different.js`](./examples/different.js).
#### Synopsis
Check if the value is a valid email.
#### Example
See [`example/email.js`](./examples/email.js).
### In
#### Synopsis
Check if the value is include inside a set of values.
#### Example
See [`example/in.js`](./examples/in.js).
### Integer
#### Synopsis
Check if the value is an integer.
#### Example
See [`example/integer.js`](./examples/integer.js).
### Maximum
#### Synopsis
Check if a number is lower or equal to a given one. This also checks if a string has a length of at most a given length.
#### Example
See [`example/maximum.js`](./examples/maximum.js).
### Minimum
#### Synopsis
Check if a number is greater or equal to given one. This also checks if a string has a length of at least a given length.
#### Example
See [`example/minimum.js`](./examples/minimum.js).
### Password
#### Synopsis
Check if a value has at least one lower and uppercase letter, one digit, one symbol and at least 8 characters.
#### Example
See [`example/password.js`](./examples/password.js).
### Required
#### Synopsis
Check if a value is present and is not null.
#### Example
See [`example/required.js`](./examples/required.js).
### Same
#### Synopsis
Check if a value is equal to another.
#### Example
See [`example/same.js`](./examples/same.js).
### String
#### Synopsis
Check if a value is of type string.
#### Example
See [`example/string.js`](./examples/string.js).