# cpf_cnpj

> Validate, generate and format CPF/CNPJ numbers

Latest version **0.2.0** (published 2016-11-01) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install cpf_cnpj
pnpm add cpf_cnpj
yarn add cpf_cnpj
bun add cpf_cnpj
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2016-11-01 |
| First published | 2013-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 116 |
| Author | Nando Vieira |
| Maintainers | fnando |
| Keywords | cpf, cnpj, document |

## Links

- npm: https://www.npmjs.com/package/cpf_cnpj
- Repository: https://github.com/fnando/cpf_cnpj.js
- Homepage: https://github.com/fnando/cpf_cnpj.js#readme
- Issues: https://github.com/fnando/cpf_cnpj.js/issues
- npm.io page: https://npm.io/package/cpf_cnpj

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2016-11-01
- 0.1.1 — 2016-06-21
- 0.1.0 — 2016-06-21
- 0.0.4 — 2015-10-15
- 0.0.2 — 2013-11-05
- 0.0.1 — 2013-11-05

## README

# CPF/CNPJ

This package does some [CPF](http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas)/[CNPJ](http://en.wikipedia.org/wiki/CNPJ) magic. It allows you to create, validate and format CPF/CNPJ.

## Installation

Using bower:

    $ bower install cpf_cnpj --save

Using NPM:

    $ npm install cpf_cnpj --save

## Usage

```js
// Node.js-specific
var CPF = require("cpf_cnpj").CPF;
var CNPJ = require("cpf_cnpj").CNPJ;

CPF.isValid("532.820.857-96");
//=> true

CPF.strip("532.820.857-96");
//=> 53282085796

CPF.format("53282085796");
//=> 532.820.857-96

CPF.generate(true); // generate formatted number
//=> 838.684.734-40

CPF.generate(); // generate unformatted number
//=> 72777632898

//==========================================================

CNPJ.isValid("41.381.074/6738-65");
//=> true

CNPJ.strip("41.381.074/6738-65");
//=> 41381074673865

CNPJ.format("41381074673865");
//=> 41.381.074/6738-65

CNPJ.generate(true); // generate formatted number
//=> 54.385.406/3140-07

CNPJ.generate(); // generate unformatted number
//=> 07033324230766
```

### Strict Validation

By default, validations will strip any characters you provide. This means that the following is valid, because only numbers will be considered:

```js
CNPJ.isValid("41#381#074-----6738\n\n65");
//=> true

CNPJ.strip("41#381#074-----6738\n\n65");
//=> 41381074673865
```

If you want to strict validate strings, use the following signature:

```js
CPF.isValid(number, strict);
CNPJ.isValid(number, strict);
```

The same example would now return `false`:

```js
CNPJ.isValid("41#381#074-----6738\n\n65", true);
//=> false
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am "Added some feature"`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

---
_Source: https://npm.io/package/cpf_cnpj · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
