cpf_cnpj

WebJar for cpf_cnpj

License

License

MIT
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

cpf_cnpj
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

cpf_cnpj
WebJar for cpf_cnpj
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/fnando/cpf_cnpj.js

Download cpf_cnpj

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/cpf_cnpj/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>cpf_cnpj</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/cpf_cnpj/
implementation 'org.webjars.bower:cpf_cnpj:0.0.3'
// https://jarcasting.com/artifacts/org.webjars.bower/cpf_cnpj/
implementation ("org.webjars.bower:cpf_cnpj:0.0.3")
'org.webjars.bower:cpf_cnpj:jar:0.0.3'
<dependency org="org.webjars.bower" name="cpf_cnpj" rev="0.0.3">
  <artifact name="cpf_cnpj" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='cpf_cnpj', version='0.0.3')
)
libraryDependencies += "org.webjars.bower" % "cpf_cnpj" % "0.0.3"
[org.webjars.bower/cpf_cnpj "0.0.3"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

CPF/CNPJ

Build Status Code Climate Gem Version

This gem does some CPF/CNPJ magic. It allows you to create, validate and format CPF/CNPJ, even through the command-line.

Just making my life easier when filling these damn numbers on internet bankings and government sites.

For ActiveModel/ActiveRecord validations, please check https://github.com/fnando/validators.

Installation

Add this line to your application's Gemfile:

gem "cpf_cnpj"

And then execute:

$ bundle

Or install it yourself as:

$ gem install cpf_cnpj

Usage

Ruby API

This library has the same API for both CNPJ/CPF, so only one of them is documented below.

require "cpf_cnpj"

CPF.valid?(number)    # Check if a CPF is valid
CPF.generate          # Generate a random CPF number
CPF.generate(true)    # Generate a formatted number

cpf = CPF.new(number)
cpf.formatted         # Return formatted CPF (xxx.xxx.xxx-xx)
cpf.stripped          # Return stripped CPF (xxxxxxxxxxx)
cpf.valid?            # Check if CPF is valid

Strict Validation

By default, validations will strip any characters that aren't numbers. This means that 532#####820------857\n96 is considered a valid number. To perform a strict validation use strict: true.

CPF.valid?(number, strict: true)

Command-line

This library gives you two binaries: cpf and cnpj.

$ cpf --check 532.820.857-96
$ $?
0

$ cpf --check 53282085796
$ $?
0

$ cpf --format 53282085796
532.820.857-96

$ cpf --strip 532.820.857-96
53282085796

$ cpf --generate
417.524.931-17

$ cpf --generate --strip
76001454809

$ echo 76001454809 | cpf -f
760.014.548-09

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

Versions

Version
0.0.3