Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/validointi/validointi
https://github.com/validointi/validointi
angular
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/validointi/validointi
- Owner: validointi
- License: mit
- Created: 2022-05-27T12:10:56.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-20T08:25:27.000Z (3 months ago)
- Last Synced: 2024-11-07T18:56:42.547Z (3 months ago)
- Topics: angular
- Language: TypeScript
- Homepage: https://validointi.github.io/
- Size: 2.25 MB
- Stars: 24
- Watchers: 4
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-angular - validointi - This is a library to help you validate your template driven forms. (Table of contents / Third Party Components)
- fucking-awesome-angular - validointi - This is a library to help you validate your template driven forms. (Table of contents / Third Party Components)
- fucking-awesome-angular - validointi - This is a library to help you validate your template driven forms. (Table of contents / Third Party Components)
README
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
# Validointi
![logo](assets/logo.ico)
## We finsish the validation debate
# @validointi/core
This is a library to help you validate your template driven forms.
## Installation
To install this library, run:
```bash
$ npm install @validointi/core --save
```## Using it in your project.
You can use this library by importing the directives and services in the components you want to use them in.
First you register your validation function to the service like this:
```ts
#vr = inject(ValidatorRegistryService);validate = this.#vr.registerValidator('sample-data', validateSampleData);
```a validation function can look like this:
```ts
async function validateSampleData(data: SampleData, field?: string): Promise {
/**
* In here we use Vest to validate the data.
* However, you can validate the data however you want.
*/
const errors = await suite(data, field).getErrors();
return Object.entries(errors).reduce((acc, [key, err]) => {
acc[key] = err;
return acc;
}, {} as ValidationErrors);
}
```> **_Pro Tip:_** When you use vest, you can use the `createVestAdapter(suite)` function to create a validation function that can be used with this library.
>
> ```ts
> validate = this.#vr.registerValidator('sample-data', createVestAdapter(suite));
> ```
>
> will make sure the vest results are formatted correctly for this library.The only restriction is that the function must return a Promise<[ValidationErrors](https://github.com/validointi/validointi/blob/03249cb8d516bf88a638e30fba12a7d2783eb37c/projects/validointi/core/src/lib/validator.types.ts#L10-L12)>.
After that you can use the directive in your template like this:
```html
Name
```
From this point the form will be validated on `formControl.valueChanges` and errors coming from the function will be set on the corresponding formControl.
## Contributors
Jeffrey Bosch
💻 📖 💡 🔧 🚧
Sander Elias
💻 📖 💡 🚧