1.0.16 • Published 9 months ago

@felte/validator-vest v1.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@felte/validator-vest

Tests Bundle size NPM Version codecov

A package to help you handle validation with Vest in Felte.

Installation

npm install --save @felte/validator-vest vest

# Or, if you use yarn

yarn add @felte/validator-vest vest

Usage

Extend Felte by calling validator and adding your suite to its suite.

import { validator } from '@felte/validator-vest';
import { create, enforce, test } from 'vest';

const suite = create('form', (data) => {
  test('email', 'Email is required', () => {
    enforce(data.email).isNotEmpty();
  });
  test('password', 'Password is required', () => {
    enforce(data.password).isNotEmpty();
  });
});

const { form } = createForm({
  // ...
  extend: validator({ suite }), // or `extend: [validator({ suite })],`
  // ...
});

OR use the validateSuite function directly in the validate option of createForm. (No need to extend Felte).

import { validateSuite } from '@felte/validator-vest';
import { create, enforce, test } from 'vest';

const suite = create('form', (data) => {
  test('email', 'Email is required', () => {
    enforce(data.email).isNotEmpty();
  });
  test('password', 'Password is required', () => {
    enforce(data.password).isNotEmpty();
  });
});

const { form } = createForm({
  // ...
  validate: validateSuite(suite),
  // ...
});

Warnings

This validator will update the warnings store with the messages returned from any test marked with warn():

import { validator } from '@felte/validator-vest';
import { create, enforce, test, warn } from 'vest';

const suite = create('form', (data) => {
  test('email', 'Email is required', () => {
    enforce(data.email).isNotEmpty();
  });
  test('password', 'Password is required', () => {
    enforce(data.password).isNotEmpty();
  });

  test('password', 'Password not secure', () => {
    warn();
    // We only warn if the user has already started typing a value
    if (!data.password) return;
    enforce(data.password).longerThanOrEquals(8);
  });
});

const { form } = createForm({
  // ...
  extend: validator({ suite }), // or `extend: [validator({ suite })],`
  // ...
});
1.0.16

9 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.11

2 years ago

1.0.12

1 year ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.0-next.19

2 years ago

1.0.1

2 years ago

1.0.0-next.18

2 years ago

1.0.0

2 years ago

1.0.0-next.17

2 years ago

1.0.0-next.16

2 years ago

1.0.0-next.11

2 years ago

1.0.0-next.10

2 years ago

1.0.0-next.15

2 years ago

1.0.0-next.14

2 years ago

1.0.0-next.13

2 years ago

1.0.0-next.12

2 years ago

1.0.0-next.0

2 years ago

1.0.0-next.1

2 years ago

1.0.0-next.2

2 years ago

1.0.0-next.22

2 years ago

1.0.0-next.21

2 years ago

1.0.0-next.20

2 years ago

0.1.0

2 years ago

1.0.0-next.3

2 years ago

1.0.0-next.4

2 years ago

1.0.0-next.5

2 years ago

1.0.0-next.6

2 years ago

1.0.0-next.7

2 years ago

0.0.5

2 years ago

1.0.0-next.8

2 years ago

0.0.4

2 years ago

1.0.0-next.9

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago