Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add sections to integrations #13

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ yarn add validations-br

### Parâmetros

| Key | Type | Description |
| :--- | :---: | ---: |
| Key | Type | Description |
| :---- | :--------------------------------------------------: | ---------------------------: |
| type | `cnpj \| cpf \| cep \| email \| pis \| phone \| uf` | Type of data to be validated |
| value | `string` | Value that will be validated |
| value | `string` | Value that will be validated |

```js
import { useValidationsBR } from 'validations-br';
Expand Down Expand Up @@ -136,6 +136,46 @@ const email = 'johndoe@gmail.com';
const isValid = validateEmail(email);
```

# Integrations

## With Yup

```js
import { validateCNPJ } from "validations-br";
import * as Yup from "yup";

try {
const schema = Yup.string().test(
"is-cnpj",
"CNPJ is not valid",
(value) => validateCNPJ(value)
);

await schema.validate(cnpj);
} catch(err) {
console.log(err.message);
}
```

## With Joi

```js
import { validateCNPJ } from "validations-br";
import Joi from "joi";

try {
const schema = Joi.string().custom(validateCNPJ, "Validate CNPJ");

const { value } = schema.validate(cnpj);

if (!value) {
throw Error("CNPJ is not valid");
}
} catch(err) {
console.log(err.message);
}
```

# Contributing

Feel free to contribute to the project. We only ask that:
Expand Down
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ yarn add validations-br

### Parâmetros

| Chave | Tipo | Descrição |
| :--- | :---: | ---: |
| Chave | Tipo | Descrição |
| :---- | :--------------------------------------------------: | --------------------------------: |
| type | `cnpj \| cpf \| cep \| email \| pis \| phone \| uf` | Tipo de dados que serão validados |
| value | `string` | Valor que será validado |
| value | `string` | Valor que será validado |

```js
import { useValidationsBR } from 'validations-br';
Expand Down Expand Up @@ -136,6 +136,45 @@ const email = 'johndoe@gmail.com';
const isValid = validateEmail(email);
```

# Integrações

## Com Yup

```js
import { validateCNPJ } from "validations-br";
import * as Yup from "yup";

try {
const schema = Yup.string().test(
"is-cnpj",
"CNPJ is not valid",
(value) => validateCNPJ(value)
);

await schema.validate(cnpj);
} catch(err) {
console.log(err.message);
}
```

## Com Joi

```js
import { validateCNPJ } from "validations-br";
import Joi from "joi";

try {
const schema = Joi.string().custom(validateCNPJ, "Validate CNPJ");

const { value } = schema.validate(cnpj);

if (!value) {
throw Error("CNPJ is not valid");
}
} catch(err) {
console.log(err.message);
}
```

# Como contribuir

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "validations-br",
"version": "1.0.3",
"version": "1.0.4",
"description": "A validator to BR informations",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down