{"id":13515907,"url":"https://github.com/fiverr/passable","last_synced_at":"2025-04-06T22:09:36.880Z","repository":{"id":38372457,"uuid":"81592021","full_name":"fiverr/passable","owner":"fiverr","description":"Declarative data validations.","archived":false,"fork":false,"pushed_at":"2023-07-18T22:14:03.000Z","size":4072,"stargazers_count":100,"open_issues_count":13,"forks_count":7,"subscribers_count":61,"default_branch":"master","last_synced_at":"2025-03-30T19:08:52.490Z","etag":null,"topics":["data-validation","isomorphic","isomorphic-validations","validations"],"latest_commit_sha":null,"homepage":"https://fiverr.github.io/passable/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fiverr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-02-10T18:04:04.000Z","updated_at":"2024-07-15T09:12:01.000Z","dependencies_parsed_at":"2024-01-13T19:25:43.209Z","dependency_job_id":"920c4852-89f0-4bd2-8990-0fd09000f8dd","html_url":"https://github.com/fiverr/passable","commit_stats":{"total_commits":306,"total_committers":21,"mean_commits":"14.571428571428571","dds":0.5816993464052287,"last_synced_commit":"43f4d6bbde55200fabfca1d6af74f5e1580d2003"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiverr%2Fpassable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiverr%2Fpassable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiverr%2Fpassable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiverr%2Fpassable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fiverr","download_url":"https://codeload.github.com/fiverr/passable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-validation","isomorphic","isomorphic-validations","validations"],"created_at":"2024-08-01T05:01:17.248Z","updated_at":"2025-04-06T22:09:36.858Z","avatar_url":"https://github.com/fiverr.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# ![Passable](https://cdn.rawgit.com/fiverr/passable/master/docs/_assets/logo.png?raw=true \"Passable\")\n\nDeclarative data validations.\n\n[![npm version](https://badge.fury.io/js/passable.svg)](https://badge.fury.io/js/passable) [![Build Status](https://travis-ci.org/fiverr/passable.svg?branch=master)](https://travis-ci.org/fiverr/passable)\n\n\n- [Documentation homepage](https://fiverr.github.io/passable/)\n- [Try it live](https://stackblitz.com/edit/passable-example?file=validate.js)\n- [Getting started](https://fiverr.github.io/passable/#/./getting_started/writing_tests).\n\n## What is Passable?\nPassable is a library for JS applications for writing validations in a way that's structured and declarative.\n\nInspired by the syntax of modern unit testing framework, passable validations are written as a spec or a contract, that reflects your form structure.\nYour validations run in production code, and you can use them in any framework (or without any framework at all).\n\nThe 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.\n\nMuch like most testing frameworks, Passable comes with its own assertion function, [enforce](https://fiverr.github.io/passable/#/./enforce.md), all error based assertion libraries are supported.\n\n## Key features\n1. [Non failing tests](https://fiverr.github.io/passable/#/test/warn_only_tests).\n2. [Conditionally running tests](https://fiverr.github.io/passable/#/test/specific).\n3. [Async validations](https://fiverr.github.io/passable/#/test/async).\n4. [Test callbacks](https://fiverr.github.io/passable/#/getting_started/callbacks).\n\n---\n\n## Syntactic differences from testing frameworks\n\nSince 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:\n\n- Your test function is not available globally, it is an argument passed to your suite's callback.\n- Each test has two string values before its callback, one for the field name, and one for the error returned to the user.\n- 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.\n\n```js\n// validation.js\nimport passable, { enforce } from 'passable';\n\nconst validation = (data) =\u003e passable('NewUserForm', (test) =\u003e {\n\n    test('username', 'Must be at least 3 chars', () =\u003e {\n        enforce(data.username).longerThanOrEquals(3);\n    });\n\n    test('email', 'Is not a valid email address', () =\u003e {\n        enforce(data.email)\n            .isNotEmpty()\n            .matches(/[^@]+@[^\\.]+\\..+/g);\n    });\n});\n\nexport default validation;\n```\n\n```js\n// myFeature.js\nimport validation from './validation.js';\n\nconst res = validation({\n    username: 'example',\n    email: 'email@example.com'\n});\n\nres.hasErrors() // returns whether the form has errors\nres.hasErrors('username') // returns whether the 'username' field has errors\nres.getErrors() // returns an object with an array of errors per field\nres.getErrors('username') // returns an array of errors for the `username` field\n```\n\n## \"BUT HEY! I ALREADY USE X VALIDATION LIBRARY! CAN IT WORK WITH PASSABLE?\"\nAs 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.\n\nThere are a [few more ways](https://fiverr.github.io/passable/#/./test/how_to_fail) 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.\n\nFor example, if you use a [different assertion libraries](https://fiverr.github.io/passable/#/./compatability/assertions) such as `chai` (expect) or `v8n`, you can simply use it instead of enforce, and it should work straight out of the box.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiverr%2Fpassable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffiverr%2Fpassable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiverr%2Fpassable/lists"}