2.8.0 • Published 6 months ago

@uireact/validator v2.8.0

Weekly downloads
-
License
GNU
Repository
-
Last release
6 months ago

@UiReact tools

UiReact icon

These are a set of tools that we created and are exported as part of the @uireact library, these tools doesn't need the foundation / view packages to work as they don't export UI, instead are helper functions that could work on any React/Typescript project.

@uireact/validator

This packages exports a class for validating data. This is commonly used to validate data received from a form.

We have added multiple validations like:

  • required
  • type
  • phone
  • greaterThan
  • range
  • dateRange
  • length
  • lessThan

For the full documentation you can visit @uireact/validator.

Usage

  1. You need to create a schema where each field has its own set of rules:
import { UiValidator } from '@uireact/validator';

const validator = new UiValidator();

const schema = {
    firstName: validator.ruler().isRequired('The first name is required')
};
  1. Then you can call the function validate() with your data and schema objects:
const data = {
    firstName: 'Felipe'
};

const result = validator.validate(schema, data);
  1. The result will bring 2 properties:

passed - If the validation successeded errors - The errors found during the validation

The errors property is keyed with properties that matches the field name of the data object passed:

console.log(`Passed: ${result.passed}`);

if (result.errors) {
    const { firstName } = result.errors;

    if (firstName?.length > 0) {
        console.log(`Error: ${firstName[0].message}`)
    }
}

What is @UiReact library?

This is a React UI library, that defines a customizable theme object that powers all colorations, texts, sizes, etc.. Across your react application.

We are built using framer-motion for great animations and styled-components for easy CSS management.

You should visit our docs page for all information @uireact docs.

2.5.0

6 months ago

2.7.0

6 months ago

2.6.0

6 months ago

2.8.0

6 months ago

2.4.1

10 months ago

2.4.0

10 months ago

1.8.0

10 months ago

1.7.0

10 months ago

1.6.0

10 months ago

2.3.0

10 months ago

2.2.0

10 months ago

2.3.1

10 months ago

2.1.0

10 months ago

2.0.1

10 months ago

1.5.4

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

2 years ago

0.5.0

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago