GithubHelp home page GithubHelp logo

thbland / vest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ealush/vest

0.0 1.0 0.0 9.99 MB

Vest ✅ Declarative validations framework

Home Page: https://ealush.com/vest/

License: MIT License

JavaScript 96.95% Shell 0.83% HTML 0.61% TypeScript 1.61%

vest's Introduction

Vest

Vest 🦺 Declarative Validation Testing

Github Stars Npm downloads

npm version Build Status Known Vulnerabilities minifiedSize

Join discord

Tutorials

Step By Step React Tutorial

Release Notes

🦺 What is Vest?

Vest is a validations library for JS apps that derives its syntax from modern JS unit testing frameworks such as Mocha or Jest. It is easy to learn due to its use of already common declarative patterns. It works great with user-input validation and with validating upon user interaction to provide the best possible user experience.

The idea behind Vest is that your validations can be described as a 'spec' or a contract that reflects your form or feature structure. Your validations run in production, and they are framework agnostic - meaning Vest works well with React, Angular, Vue, or even without a framework at all.

Using Vest for form validation can reduce bloat, improve feature readability and maintainability.

Basic Example full

Memoized async test memo

✅ Motivation

Writing forms is an integral part of building web apps, and even though it may seem trivial at first - as your feature grows over time, so does your validation logic grows in complexity.

Vest tries to remediate this by separating validation logic from feature logic so it is easier to maintain over time and refactor when needed.

✨ Vest's features

  • 🎨 Framework agnostic (BYOUI)
  • ⚡️ Rich, extendable, assertions library (enforce) (doc)
  • 🚥 Multiple validations for the same field
  • ⚠️ Warning (non failing) tests (doc)
  • 📝 Validate only the fields the user interacted with (doc)
  • ⏳ Memoize async validations to reduce calls to the server (doc)
  • 🚦 Test grouping (doc)

Example code (Run in sandbox)

import vest, { test } from 'vest';

export default vest.create('user_form', (data = {}, currentField) => {
  vest.only(currentField);

  test('username', 'Username is required', () => {
    enforce(data.username).isNotEmpty();
  });

  test('username', 'Username is too short', () => {
    enforce(data.username).longerThanOrEquals(3);
  });

  test('password', 'Password is required', () => {
    enforce(data.password).isNotEmpty();
  });

  test('password', 'Password must be at least 6 chars long', () => {
    enforce(data.password).longerThanOrEquals(6);
  });

  test('password', 'Password is weak, Maybe add a number?', () => {
    vest.warn();
    enforce(data.password).matches(/[0-9]/);
  });

  if (data.password) {
    test('confirm_password', 'Passwords do not match', () => {
      enforce(data.confirm_password).equals(data.password);
    });
  }

  test('email', 'Email Address is not valid', () => {
    enforce(data.email).isEmail();
  });

  test('tos', () => {
    enforce(data.tos).isTruthy();
  });
});

Why Vest?

  • 🧠 Vest is really easy to learn. You can take your existing knowledge of unit tests and transfer it to validations.
  • ✏️ Vest takes into account user interaction and warn only validations.
  • 🧱 Your validations are structured, making it very simple to read and write. All validation files look the same.
  • 🖇 Your validation logic is separate from your feature logic, preventing the spaghetti code that's usually involved with writing validations.
  • 🧩 Validation logic is easy to share and reuse across features.

Vest is an evolution of Passable by Fiverr.

vest's People

Contributors

adife avatar codechips avatar dependabot-preview[bot] avatar ealush avatar eyalcohen4 avatar galitpauz avatar ganeshpatil0101 avatar gaspoute avatar gaweki avatar hpsharon avatar kapalex avatar lirantal avatar moses3301 avatar norbertluszkiewicz avatar omrilugasi avatar ronen-e avatar syncush avatar vligas avatar yakkomajuri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.