-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bd4904
commit 92cc24d
Showing
1 changed file
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,16 @@ | |
|
||
> JavaScript validation engine | ||
![Version](https://img.shields.io/github/package-json/v/theonlyducks/validation.js) | ||
![Project Size](https://img.shields.io/bundlephobia/min/@theonlyducks/validation.js@latest) | ||
![Dependencies](https://img.shields.io/github/languages/top/theonlyducks/validation.js) | ||
![Licence](https://img.shields.io/github/license/theonlyducks/validation.js) | ||
|
||
## Table of contents | ||
|
||
- [Getting started](#getting-started) | ||
- [Documentation](#documentation) | ||
|
||
## Documentation | ||
|
||
See | ||
|
@@ -16,8 +26,10 @@ yarn add @theonlyducks/valitaion.js | |
|
||
### Usage | ||
|
||
#### Basic usage | ||
|
||
```js | ||
import Validate from "valitaion.js"; | ||
import Validate, { AssertError } from "valitaion.js"; | ||
|
||
const name = 'John Doe' | ||
const props = new Validate(); | ||
|
@@ -27,6 +39,51 @@ try { | |
props.assertOne(); | ||
console.log('valid'); | ||
} catch (error) { | ||
console.error('errors', errors.data); | ||
if (error instanceof AssertError) { | ||
console.error('errors', errors.data); | ||
} | ||
} | ||
``` | ||
|
||
#### Advanced usage | ||
|
||
```js | ||
import Validate, { AssertError } from "valitaion.js"; | ||
|
||
const data = { | ||
name: 'John Doe', | ||
email: '[email protected]' | ||
}; | ||
|
||
const validate = new Validate(); | ||
validate | ||
.addKey('name').required().notEmpty().isString() | ||
.addKey('email').required().notEmpty().isString().isEmail(); | ||
|
||
try { | ||
validate.assert(data); | ||
console.log('valid'); | ||
} catch (error) { | ||
if (error instanceof AssertError) { | ||
console.error('errors', errors.data); | ||
} | ||
} | ||
``` | ||
|
||
## Development | ||
|
||
Install | ||
|
||
```shell | ||
yarn | ||
``` | ||
|
||
Run tests | ||
|
||
```shell | ||
yarn test | ||
``` | ||
|
||
## License | ||
|
||
[MIT](https://opensource.org/licenses/MIT) © [The Only Ducks](https://github.com/theonlyducks) |