Socket
Socket
Sign inDemoInstall

cpf_cnpj

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cpf_cnpj

Validate, generate and format CPF/CNPJ numbers


Version published
Weekly downloads
5.9K
increased by3.01%
Maintainers
1
Install size
25.3 kB
Created
Weekly downloads
 

Readme

Source

CPF/CNPJ

This package does some CPF/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

// 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:

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:

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

The same example would now return false:

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

Keywords

FAQs

Last updated on 01 Nov 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc