All Projects → fiverr → Passable

fiverr / Passable

Licence: mit
Declarative data validations.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Passable

Typescript Hapi React Hot Loader Example
Simple TypeScript React Hot Loading example with Hapi Server-side rendering
Stars: ✭ 44 (-52.69%)
Mutual labels:  isomorphic
Danf
Danf is a Node.js full-stack isomorphic OOP framework allowing to code the same way on both client and server sides. It helps you to make deep architectures and handle asynchronous flows in order to help in producing scalable, maintainable, testable and performant applications.
Stars: ✭ 58 (-37.63%)
Mutual labels:  isomorphic
Dumb Passwords
Don't let your user be a victim of their own action
Stars: ✭ 77 (-17.2%)
Mutual labels:  validations
Ansi Escape Sequences
A simple, isomorphic library containing all known terminal ansi escape codes and sequences.
Stars: ✭ 44 (-52.69%)
Mutual labels:  isomorphic
Cross Fetch
Universal WHATWG Fetch API for Node, Browsers and React Native.
Stars: ✭ 1,063 (+1043.01%)
Mutual labels:  isomorphic
Saul
Data validation and conformation library for Elixir.
Stars: ✭ 62 (-33.33%)
Mutual labels:  data-validation
Webpack Isomorphic Dev Middleware
The webpack-dev-middleware, but for isomorphic applications
Stars: ✭ 38 (-59.14%)
Mutual labels:  isomorphic
Preact Redux Isomorphic
preact-redux-isomorphic PWA SPA SSR best practices and libraries in under 80kB page size (for live demo click the link below)
Stars: ✭ 85 (-8.6%)
Mutual labels:  isomorphic
Dry Validation
Validation library with type-safe schemas and rules
Stars: ✭ 1,087 (+1068.82%)
Mutual labels:  data-validation
Nivo
nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries
Stars: ✭ 9,550 (+10168.82%)
Mutual labels:  isomorphic
Jose
Universal "JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK with no dependencies
Stars: ✭ 1,029 (+1006.45%)
Mutual labels:  isomorphic
Universal React Demo
ES6 demo of a simple but scalable React app with react-router, code splitting, server side rendering, and tree shaking.
Stars: ✭ 50 (-46.24%)
Mutual labels:  isomorphic
Vee Validate
✅ Form Validation for Vue.js
Stars: ✭ 8,820 (+9383.87%)
Mutual labels:  validations
Hapi React Hot Loader Example
Simple React Hot Loading example with Hapi Server-side rendering
Stars: ✭ 44 (-52.69%)
Mutual labels:  isomorphic
React Base
atSistemas React/Redux Isomorphic Platform
Stars: ✭ 82 (-11.83%)
Mutual labels:  isomorphic
Push Starter
React Redux Starter with SSR 🤖
Stars: ✭ 43 (-53.76%)
Mutual labels:  isomorphic
Koot
Koot是基于React和Koa的WEB全栈技术解决方案。
Stars: ✭ 59 (-36.56%)
Mutual labels:  isomorphic
Egg Vue Webpack Boilerplate
Egg Vue Server Side Render (SSR) / Client Side Render (CSR)
Stars: ✭ 1,302 (+1300%)
Mutual labels:  isomorphic
Webpack Isomorphic Tools
Server-side rendering for your Webpack-built applications (e.g. React)
Stars: ✭ 1,258 (+1252.69%)
Mutual labels:  isomorphic
Isomorphine
Require server-side modules from the browser, remotely.
Stars: ✭ 66 (-29.03%)
Mutual labels:  isomorphic

Passable

Declarative data validations.

npm version Build Status

What is Passable?

Passable is a library for JS applications for writing validations in a way that's structured and declarative.

Inspired by the syntax of modern unit testing framework, passable validations are written as a spec or a contract, that reflects your form structure. Your validations run in production code, and you can use them in any framework (or without any framework at all).

The idea behind passable is that you can easily adopt its very familiar syntax, and transfer your knowledge from the world of testing to your form validations.

Much like most testing frameworks, Passable comes with its own assertion function, enforce, all error based assertion libraries are supported.

Key features

  1. Non failing tests.
  2. Conditionally running tests.
  3. Async validations.
  4. Test callbacks.

Syntactic differences from testing frameworks

Since Passable is running in production environment, and accommodates different needs, some changes to the basic unit test syntax have been made, to cover the main ones quickly:

  • Your test function is not available globally, it is an argument passed to your suite's callback.
  • Each test has two string values before its callback, one for the field name, and one for the error returned to the user.
  • Your suite accepts another argument after the callback - name (or array of names) of a field. This is so you can run tests selectively only for changed fields.
// validation.js
import passable, { enforce } from 'passable';

const validation = (data) => passable('NewUserForm', (test) => {

    test('username', 'Must be at least 3 chars', () => {
        enforce(data.username).longerThanOrEquals(3);
    });

    test('email', 'Is not a valid email address', () => {
        enforce(data.email)
            .isNotEmpty()
            .matches(/[^@][email protected][^\.]+\..+/g);
    });
});

export default validation;
// myFeature.js
import validation from './validation.js';

const res = validation({
    username: 'example',
    email: '[email protected]'
});

res.hasErrors() // returns whether the form has errors
res.hasErrors('username') // returns whether the 'username' field has errors
res.getErrors() // returns an object with an array of errors per field
res.getErrors('username') // returns an array of errors for the `username` field

"BUT HEY! I ALREADY USE X VALIDATION LIBRARY! CAN IT WORK WITH PASSABLE?"

As a general rule, Passable works similarly to unit tests in term that if your test throws an exception, it is considered to be failing. Otherwise, it is considered to be passing.

There are a few more ways to handle failures in order to ease migration, and in most cases, you can move your validation logic directly to into Passable with only a few adjustments.

For example, if you use a different assertion libraries such as chai (expect) or v8n, you can simply use it instead of enforce, and it should work straight out of the box.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].