# @fnando/cpf

> Validate, generate and format CPF numbers

Latest version **1.0.2** (published 2020-07-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fnando/cpf
pnpm add @fnando/cpf
yarn add @fnando/cpf
bun add @fnando/cpf
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-07-21 |
| First published | 2018-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 43 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 168 |
| Author | Nando Vieira |
| Maintainers | fnando |
| Keywords | cpf, document |

## Links

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

## 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

- 1.0.2 (latest) — 2020-07-21
- 1.0.1 — 2020-02-19
- 1.0.0 — 2020-02-19
- 0.1.1 — 2018-10-26
- 0.1.0 — 2018-04-04

## README

# CPF

[![Build Status](https://travis-ci.org/fnando/cpf.svg?branch=master)](https://travis-ci.org/fnando/cpf)
[![NPM package version](https://img.shields.io/npm/v/@fnando/cpf.svg)](https://www.npmjs.com/package/@fnando/cpf)
![License: MIT](https://img.shields.io/npm/l/@fnando/cpf.svg)
![Minified size](http://img.badgesize.io/fnando/cpf/master/web/cpf.min.js.svg?label=cpf+min+size)
![Minified+Gzip size](http://img.badgesize.io/fnando/cpf/master/web/cpf.min.js.svg?compression=gzip&label=cpf+min%2Bgzip+size)

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

**HINT:** Check out the CNPJ counter part available at
<https://github.com/fnando/cnpj>.

## Installation

This lib is available as a NPM package. To install it, use the following
command:

```
npm install @fnando/cpf --save
```

If you're using Yarn (and you should):

```
yarn add @fnando/cpf
```

## Usage

```js
// Node.js-specific
const cpf = require("@fnando/cpf/commonjs");

// @import
import * as cpf from "@fnando/cpf"; // import the whole library
import { isValid as isValidCpf } from "@fnando/cpf"; // import just one function

// import via <script>; the lib will available as window.cpf
// <script src="cpf.js"></script>

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

cpf.isValid("53282085796");
//=> 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
```

On the web, without transformation, just use `web/cpf.min.js`.

### 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
cpf.isValid("101#688!!!!!!542......36");
//=> true

cpf.strip("101#688!!!!!!542......36");
//=> 10168854236
```

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

```js
cpf.isValid(number, strict);
```

The same example would now return `false`:

```js
cpf.isValid("101#688!!!!!!542......36", true);
//=> false
```

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