Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ezier-project/validate
An ezier validator for nodejs.
https://github.com/ezier-project/validate
chai ezier mocha nodejs prettier swc typescript validator
Last synced: 6 days ago
JSON representation
An ezier validator for nodejs.
- Host: GitHub
- URL: https://github.com/ezier-project/validate
- Owner: ezier-project
- License: mit
- Created: 2022-04-19T14:10:13.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-12T09:24:04.000Z (over 2 years ago)
- Last Synced: 2024-11-17T18:07:41.687Z (2 months ago)
- Topics: chai, ezier, mocha, nodejs, prettier, swc, typescript, validator
- Language: TypeScript
- Homepage: https://npmjs.com/@ezier/validate
- Size: 236 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Ezier Validator
An ezier validator for nodejs.
![npm bundle size](https://img.shields.io/bundlephobia/min/@ezier/validate?style=for-the-badge) ![npm](https://img.shields.io/npm/dm/@ezier/validate?style=for-the-badge) ![NPM](https://img.shields.io/npm/l/@ezier/validate?style=for-the-badge) ![npm](https://img.shields.io/npm/v/@ezier/validate?style=for-the-badge)
# Why?
**This validator allows you to validate your objects with eze.
Nothing more, nothing less.*****Also used in the Fronvo [server](https://github.com/Fronvo/fronvo)***
# Installing
```
npm i @ezier/validate
```# Documentation
**Documentation for the Ezier Validator can be found at https://ezier-project.github.io/validate/.**# Examples
**Validate a string's length:**
```ts
import { StringSchema } from '@ezier/validate';const schema = new StringSchema({
value: {
minLength: 5,
maxLength: 20
}
});const result = schema.validate({
value: 'some string'
});
```**Validating manually with regex:**
```ts
import { v4 } from 'uuid';const uuidSchema = new StringSchema({
uuid: {
regex: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/
},
});uuidSchema.validate({ uuid: v4() });
```**Or with provided types:**
```ts
import { v4 } from 'uuid';const uuidSchema = new StringSchema({
uuid: {
type: 'uuid'
},
});uuidSchema.validate({ uuid: v4() });
```**With support for optional fields:**
```ts
const schema = new StringSchema({
provideThis: {
minLength: 8,
maxLength: 60,
type: 'email',
},orThis: {
minLength: 8,
maxLength: 30,
regex: /^[a-zA-Z0-9]+$/,
optional: true
},
});schema.validate({
provideThis: '[email protected]'
});
```**Getting error info:**
```ts
for (const errorObjectIndex in result) {
const errorObject = result[Number(errorObjectIndex)];console.log(`[${errorObject.name}]: ${errorObject.message}`);
}
```**More examples located [here](https://github.com/ezier-project/validate/tree/master/examples)**
Made by [Shadofer](https://github.com/shadofer) with joy.