Skip to content

Commit

Permalink
[Patch] Use docsify (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jun 23, 2019
1 parent fa05c96 commit a89cef2
Show file tree
Hide file tree
Showing 74 changed files with 1,276 additions and 1,435 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ dev
version.json
version.txt
.version
docs
documentation/MAIN.md
documentation/assets/**/*.css
.DS_Store
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dev
.travis.yml
webpack.config.js
yarn.lock
docs
_docpress
_docs
flow-typed
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ after_success:
- node ./scripts/make_version_file.js
- chmod +x ./scripts/push_tag_to_master.sh
- if [ -n "$TRAVIS_TAG" ]; then ./scripts/push_tag_to_master.sh; fi
- chmod +x ./scripts/docs.sh
- if [ "$TRAVIS_BRANCH" == "master" -a "$TRAVIS_PULL_REQUEST" == "false" ]; then ./scripts/docs.sh; fi
- chmod +x ./scripts/prepare_next.sh
- if [ "$TRAVIS_BRANCH" != "master" ]; then ./scripts/prepare_next.sh; fi

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

# [7.1.0] - ?
# [7.1.0] - 2019-06-23

### Added
- [Minor] Added an option to directly import `test` from passable;
Expand Down
1 change: 1 addition & 0 deletions dist/passable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/passable.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/passable.min.js.map

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions docpress.json

This file was deleted.

Binary file added docs/.DS_Store
Binary file not shown.
Empty file added docs/.nojekyll
Empty file.
78 changes: 78 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ![Passable](https://cdn.rawgit.com/fiverr/passable/master/documentation/assets/img/logo.png?raw=true "Passable")

Declarative data validations.

[![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)


- [Documentation homepage](https://fiverr.github.io/passable/)
- [Try it live](https://stackblitz.com/edit/passable-example?file=validate.js)
- [Getting started](getting_started/writing_tests).

## 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](./enforce/readme.md), all error based assertion libraries are supported.

## Key features
1. [Non failing tests](test/warn_only_tests).
2. [Conditionally running tests](test/specific).
3. [Async validations](test/async).
4. [Test callbacks](getting_started/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.

```js
// 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(/[^@]+@[^\.]+\..+/g);
});
});

export default validation;
```

```js
// 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](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.

For 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.
Binary file added docs/_assets/favicon.ico
Binary file not shown.
23 changes: 23 additions & 0 deletions docs/_assets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Object.assign(window, passable);

setTimeout(() => {
console.log(`All passable functions are exposed globally,
you can try passable in your console.`);

console.log(`PASSABLE VERSION:`, passable.VERSION);

console.table(Object.keys(passable).map((item) => [item, typeof passable[item]]));

console.log(`You can try:
const data = {
useanme: 'example'
};
passable('FormName', () => {
test('username', 'Must be at least 4 chars', () => {
enforce(data.username).longerThanOrEquals(4);
});
});
`)
}, 1000);
File renamed without changes
28 changes: 28 additions & 0 deletions docs/_assets/stylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.markdown-section code {
font-size: 85%;
color: #26B4AD;
}

.app-name {
padding: 10px;
}

.sidebar-nav {
padding-left: 10px;
}

body, .anchor span, a.anchor {
color: #3C4464;
}

.token.function,.token.keyword {
color: #26B4AD
}

.token.boolean, .token.number {
color: #59d4e8;
}

.markdown-section a:hover {
color: #3a6b96;
}
16 changes: 16 additions & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

* Getting Started
* [Installation](./getting_started/installation.md)
* [Writing tests](./getting_started/writing_tests.md)
* [Passable callbacks](./getting_started/callbacks.md)
* [The `result` object](./getting_started/result.md)
* [The `test` Function](./test/index.md)
* [How to fail a test](./test/how_to_fail.md)
* [Warn only tests](./test/warn_only_tests.md)
* [Skipping tests](./test/specific.md)
* [Async tests](./test/async.md)
* [Test Utilities](./utilities/README.md)
* [Assertions with `enforce`](./enforce/README.md)
* [Enforce Rules](./enforce/rules/README.md)
* [Custom Enforce Rules](./enforce/rules/custom.md)
* [Using with assertions libraries](./compatability/assertions.md)
File renamed without changes.
10 changes: 5 additions & 5 deletions documentation/enforce/README.md → docs/enforce/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Assertions with `enforce`
`enforce` is Passable's assertion library. It allows you to run your data against [rules and conditions](./rules/README.md) and test whether it passes your validations. It is intended for validation logic that gets repeated over and over again and should not be written manually. It comes with a wide-variety of pre-built rules, but it can also be extended to support your own repeated custom logic.
`enforce` is Passable's assertion library. It allows you to run your data against [rules and conditions](enforce/rules/README.md) and test whether it passes your validations. It is intended for validation logic that gets repeated over and over again and should not be written manually. It comes with a wide-variety of pre-built rules, but it can also be extended to support your own repeated custom logic.

The way `enforce` operates is similar to most common assertion libraries - if the validation fails, it throws an Error, and if the validation succeeds, it returns the current instance of `enforce` to allow chaining more rules.

Expand Down Expand Up @@ -56,7 +56,7 @@ passable('enforcement', (test) => {

```

More on [custom enforce rules](./rules/custom.md).
More on [custom enforce rules](enforce/rules/custom.md).

## Chaining enforce functions

Expand All @@ -73,8 +73,8 @@ enforce('North Dakota, por favor').shorterThan(10).longerThan(6);
enforce('Toto, I\'ve a feeling we\'re not in Kansas anymore').notMatches(/0-9/);
```

Enforce exposes all [predefined](./rules/README.md) and [custom](./rules/custom.md) rules. You may use chaining to make multiple enfocements for the same value.
Enforce exposes all [predefined](enforce/rules/README.md) and [custom](enforce/rules/custom.md) rules. You may use chaining to make multiple enfocements for the same value.

### Table of Contents
* [Enforce Rules](./rules/README.md)
* [Custom Enforce Rules](./rules/custom.md)
* [Enforce Rules](enforce/rules/README.md)
* [Custom Enforce Rules](enforce/rules/custom.md)
Loading

0 comments on commit a89cef2

Please sign in to comment.