0.2.3 • Published 2 years ago

@ezier/validate v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Ezier Validator

npm bundle size npm NPM npm

Why?

This validator allows you to validate your objects with eze. Nothing more, nothing less.

Also used in the Fronvo server

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:

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:

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:

import { v4 } from 'uuid';

const uuidSchema = new StringSchema({
    uuid: {
        type: 'uuid'
    },
});

uuidSchema.validate({ uuid: v4() });

With support for optional fields:

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: 'anemail@gmail.com'
});

Getting error info:

for (const errorObjectIndex in result) {
    const errorObject = result[Number(errorObjectIndex)];

    console.log(`[${errorObject.name}]: ${errorObject.message}`);
}

More examples located here

Made by Shadofer with joy.

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago