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
var CPF = require("cpf_cnpj").CPF;
var CNPJ = require("cpf_cnpj").CNPJ;
CPF.isValid("532.820.857-96");
CPF.strip("532.820.857-96");
CPF.format("53282085796");
CPF.generate(true);
CPF.generate();
CNPJ.isValid("41.381.074/6738-65");
CNPJ.strip("41.381.074/6738-65");
CNPJ.format("41381074673865");
CNPJ.generate(true);
CNPJ.generate();
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");
CNPJ.strip("41#381#074-----6738\n\n65");
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);
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am "Added some feature"
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request