# @react-br-forms/cpf-cnpj-mask

> Simple input mask for brazilian CPF and CNPJ

Latest version **1.0.6** (published 2020-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @react-br-forms/cpf-cnpj-mask
pnpm add @react-br-forms/cpf-cnpj-mask
yarn add @react-br-forms/cpf-cnpj-mask
bun add @react-br-forms/cpf-cnpj-mask
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2020-09-20 |
| First published | 2020-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Juliano Grams |
| Maintainers | julianograms |
| Keywords | cpf, cnpj, mask, documento, document, input, react, brasil, brazil, br, mascara |

## Links

- npm: https://www.npmjs.com/package/@react-br-forms/cpf-cnpj-mask
- Repository: https://github.com/julianograms/react-cpf-cnpj-mask
- Homepage: https://github.com/julianograms/react-cpf-cnpj-mask#readme
- Issues: https://github.com/julianograms/react-cpf-cnpj-mask/issues
- npm.io page: https://npm.io/package/@react-br-forms/cpf-cnpj-mask

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2020-09-20
- 1.0.5 — 2020-09-20
- 1.0.4 — 2020-09-20
- 1.0.3 — 2020-09-20
- 1.0.2 — 2020-09-20
- 1.0.1 — 2020-09-20
- 1.0.0 — 2020-09-20
- 0.1.6 — 2020-09-20
- 0.1.5 — 2020-09-20
- 0.1.4 — 2020-09-20
- 0.1.3 — 2020-09-20
- 0.1.2 — 2020-09-20
- 0.1.1 — 2020-09-20

## README

# Simple CPF and CNPJ input mask.

![Azure Static Web Apps CI/CD](https://github.com/julianograms/react-cpf-cnpj-mask/workflows/Azure%20Static%20Web%20Apps%20CI/CD/badge.svg)

![ttystrudio GIF](https://imgur.com/VA7PT8i.gif)

This is an `<input />` wrapper to mask the value (**_which can be either a CPF or CNPJ_**) with the corresponding brazilian format mask, as you type. \
It will apply all the props given to it, to an input field, enabling any customization.
**No dependencies included.**

Este é um componente que encapsula um `<input />`, com o objetivo de adicionar a máscara correspondente no valor (Podendo ser CPF ou CNPJ) do input enquanto você digita.
Os props são copiados diretamente para um `<input />`, permitindo customização.
**Não possui dependendências.**

## Demo :imp:

<a href="https://agreeable-ocean-09191400f.azurestaticapps.net" target="_blank">Demo</a>

## Installation

```shell
$ yarn add @react-br-forms/cpf-cnpj-mask
```

## Example

### Basic Example

```JSX
import React, { useState } from "react";
import ReactDOM from "react-dom";
import CpfCnpj from "@react-br-forms/cpf-cnpj-mask";

const App = () => {

  const [cpfCnpj, setCpfCnpj] = useState("");
  const [mask, setMask] = useState("");

  return (
    <div>
      <CpfCnpj
        value={cpfCnpj}
        onChange={(event, type) => {
          setCpfCnpj(ev.target.value);
          setMask(type === "CPF");
        }}
      />
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById("root"));

```

### With custom props

```JSX
import React, { useState } from "react";
import ReactDOM from "react-dom";
import CpfCnpj from "@react-br-forms/cpf-cnpj-mask";

const App = () => {

  const [cpfCnpj, setCpfCnpj] = useState("");
  const [mask, setMask] = useState("");

  return (
    <div>
      <CpfCnpj
        className="customizedInput"
        placeholder="Digite um CPF ou CNPJ"
        type="tel"
        value={cpfCnpj}
        onChange={(event, type) => {
          setCpfCnpj(ev.target.value);
          setMask(type === "CPF");
        }}
      />
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById("root"));

```

## Component Props

|            Name             |          Type           | DefaultProps | Description                                                                                                                                |
| :-------------------------: | :---------------------: | :----------: | :----------------------------------------------------------------------------------------------------------------------------------------- |
|    **[`value`](#value)**    |        `String`         |     `""`     | Wrapped `<input/>` value. This value will be masked.                                                                                       |  |
| **[`onChange`](#onChange)** | `Function(event, type)` |  `() => {}`  | `event`: Wrapped `onChange` input event. The `target.value` will be masked. <br /><br /> `type`: It will return either `"CPF"` or `"CNPJ"` |
|     **[`type`](#type)**     |        `String`         |    `tel`     | Default input type is `tel`.                                                                                                               |

## About the repository

> Install the dependencies.
>
> - `npm install` or `yarn install`
>
> To start the example project in dev:
>
> - `npm run start`

## Test

> Install the dependencies.
>
> - `npm install` or `yarn install`
>
> To test the component:
>
> - `npm run test`
>
> To test the component, and watch:
>
> - `npm run test:watch`
>
> To see test coverage:
>
> - `npm run test:coverage`

## License

[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://badges.mit-license.org)

- **[MIT license](http://opensource.org/licenses/mit-license.php)**

---
_Source: https://npm.io/package/@react-br-forms/cpf-cnpj-mask · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
