GithubHelp home page GithubHelp logo

brcpfcnpj's Introduction

Hi there 👋

brcpfcnpj's People

Contributors

alfakini avatar diogobeda avatar eriknakata avatar esdras avatar prem-prakash avatar soteras avatar tiagoengel avatar vitortrin avatar williamgueiros avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

brcpfcnpj's Issues

Add support for Ecto changesets

I was thinking on adding some methods to add support for the Ecto changeset api.
Would look something like this:

model
    |> cast(params, @required_fields, @optional_fields)
    |> validate_cnpj(:cnpj, message: "Cnpj inválido')

What do you think?

cpf_valid error - nil

Guys,

I had an issue with the function cnpj_valid? when the input is "nil".

Example:

Brcpfcnpj.cpf_valid?(%Cpf{number: nil})

Result:

** (FunctionClauseError) no function clause matching in Regex.replace/4

I think would be great is the function returns "false" with nil cases.

Can I send a pull request with the fix?

Changeset validation errors problem

When adding validation errors on changeset functions, things are being added incorrectly: for example, this is how "default" errors in Ecto are being added:

errors: [name: {"can't be blank", [validation: :required]}

And this is how BrCNPJ are being added:

errors: [contract: "Document format invalid",

This means that FallbackController can't parse correctly these errors, and we're getting a run-time exception:

     ** (FunctionClauseError) no function clause matching in AppWeb.ErrorHelpers.translate_error/1

     The following arguments were given to AppWeb.ErrorHelpers.translate_error/1:
     
         # 1
         "Invalid Cnpj"
     
     Attempted function clauses (showing 1 out of 1):
     
         def translate_error({msg, opts})

Code refactoring proposal

Hello guys, thanks for writing this lib, it's really making my life easier.

Nevertheless, I feel a little confused about how things were organised in the code base. Taking by example, Brcpfcnpj holds all formatting, generation and validations functions to be called, which I understand to be the main module, but who does the hard work is Cpfcnpj module. Even being documented as the responsible module to check whether a document struct is valid or not, also has some formatting and document struct generators which, IMHO, could be somewhere else such as Cpfcnpj.Formatters and Cpfcnpj.Generators.

Let me know WYT and If you agree, I don't mind sending a PR with a few tweaks I'm thinking to be nice we could share.

[question label, pls!]

Module naming to avoid duplicated modules inside projects

Tenho visto que alguns módulos estão com nomes simples (Cpf, Cnpj) que podem gerar duplicidade em projetos que utilizam nomes parecidos dentro da sua code base.

Deixo essa issue aberta para discussões, afinal isso pode gerar breaking changes.

Não considerar certos casos como CNPJ válido

Eu percebi que há alguns casos em que certas entradas de 14 dígitos não deveriam estar sendo consideradas como CNPJ válidos.

A questão é: há casos onde me é informado entradas variadas de 14 dígitos, onde precisamos verificar se essa entrada é um CNPJ válido ou um CPF válido (removendo os 3 primeiros dígitos). E por conta disso me deparei com um caso onde tanto os 14 dígitos configuram como um CNPJ válido, quanto os últimos 11 dígitos configuram como um CPF válido (quando a realidade é que essa entrada é apenas um CPF válido).

Percebi que a solução se dá fazendo certas verificações para o caso de CNPJs e, para isso, segue uma citação que extraí desse link aqui:

Não será considerado válido CNPJ com número de ORDEM igual a 0000
Não será considerado válido CNPJ com número de ORDEM maior do que 0300 e com as três primeiras posições do número BÁSICO com 000 (zeros). Esta crítica não será feita, quando o no básico do CNPJ for igual a 00.000.000

Acredito que atualmente a lib não está levando em consideração essas regras acima na hora de validar o CNPJ. O que acha de incluirmos isso no algoritmo de validação de CNPJ? Se precisarem de um suposto CNPJ (que na verdade é um CPF) que caia nesse caso, me peçam no privado (meu e-mail: [email protected]), para que não se exponha publicamente CPF de terceiros por aqui.

License

Hi everyone :)

First of all, thanks for developing and maintaining this library. I notice the repository doesn't present any license. Is it licensed to be used on other softwares? If it is, is there any willingness to setup a license for this repository?

Thanks!

Improve random number generation

Today, the way used to create random numbers in CNPJ or CPF generation can cause a "bug" when you use that in multiple tests or sessions, generating the same sequence of CNPJ's or CPF's for all of them.

i.e.
Starts a iex session and generate a random CNPJ:
iex(1)> Brcpfcnpj.cnpj_generate results in "21546853597400"
If you starts another iex session and use the same function, you'll get the same result ("21546853597400").

To solve that problem, I suggest to change from random erlang module to rand module, which was released in Erlang 18 and improve these random number generation.

I did some tests using the rand module and this solves the problem, if you wan't I can do the changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.