williamgueiros / brcpfcnpj Goto Github PK
View Code? Open in Web Editor NEWValidação,Formatação e Gerador Cpf/Cnpj em Elixir
License: MIT License
Validação,Formatação e Gerador Cpf/Cnpj em Elixir
License: MIT License
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?
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?
Now you have new package 0.2.0
https://hex.pm/packages/brcpfcnpj
@esdras please, check your implementation is correct with the documentation ?
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})
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!]
@ulissesalmeida @VitorTrin @mvibraim
Pessoal, acho que a lib pode ser mantida por mais pessoas.
Acho que esta muito centralizada em mim.
Gostaria de saber se alguém esta afim ??
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.
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.
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!
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.
Scenario:
In this issue comment you suggested an only function to validating cpf or cnpj. May be a great idea to validate if the field is according to some document format.
This make sense when you need save contacts with some document is present but not both at the same time.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.