Coder Social home page Coder Social logo

theuves / cpf Goto Github PK

View Code? Open in Web Editor NEW
60.0 2.0 13.0 718 KB

Validar, formatar e gerar números de CPF (validate, format and generate CPF numbers 🇧🇷).

Home Page: https://twitter.com/theuves/status/1528501442910334977

License: MIT License

JavaScript 100.00%
brasil brazil cpf cpf-formate cpf-generator cpf-mask cpf-validador cpf-validate cpf-validation cpf-validator number numbers

cpf's Introduction

cpf

Functions to handle Brazilian CPF numbers

Status


Precisando de um desenvolvedor? Entre em contato: [email protected]


Installation

You can install it with npm or yarn.

Try:

  • npm: npm install cpf
  • yarn: yarn add cpf

Usage

const CPF = require('cpf');

Now, CPF is a object with some functions:

  • format
  • generate
  • isValid

CPF.format(cpf)

Format a CPF number.

Example

CPF.format('11144477735');
//=> '111.444.777-35'

Parameters

  • cpf {string} A CPF number.

Returns a string with the formatted CPF number.

CPF.generate(formatted, invalid)

Generate a random CPF number.

Parameters

  • formatted {boolean} true by default. It will generate a formatted CPF number.
  • invalid {boolean} false by default. It will generate a invalid CPF number.

Returns a CPF number.

CPF.isValid(cpf, byLength)

Check if a CPF number is valid.

Example

CPF.isValid('111.444.777-35');
// true

CPF.isValid('111.444.777-42');
// false

CPF.isValid('111.444.777-42', true);
// true

CPF.isValid('111.444.777', true);
// false

Parameters

  • cpf {string} Check if the CPF number is valid.
  • byLength {boolean} false by default. Check only if the length is valid.

Returns the check result.

License

MIT © Matheus Alves

cpf's People

Contributors

felipearomani avatar igorrafael avatar lucasteles avatar theuves 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

Watchers

 avatar  avatar

cpf's Issues

Melhorar a função format

Atualmente a função format só faz a formatação se o CPF tem 11 dígitos. Seria interessante que ela fizesse a formatação pra qualquer quantidade de dígitos, aí ela poderia ser usada durante a digitação de campos. Posso abrir um Pull Request pra fazer essa modificação.

Sobre utilização da biblioteca para projeto Web

Boa Tarde

Ola tudo bom

Gostaria de estar efetuando testes com a sua biblioteca

Como eu utilizo a mesma ?

Executei o comando em meu terminal e foi criado uma pasta node_modules

Pretendo usar em um projeto para a Web

Failed to minify the code from this file: calc-dv.js

Ao criar um projeto React usando a ferramenta "create-react-app" e instalar o modulo "cpf", no momento de fazer o "build" da aplicação encontramos o erro abaixo:

Failed to minify the code from this file: "./node_modules/cpf/lib/calc-dv.js:9"

Isso é causado porque na linha 9 do arquivo calc-dv.js é utilizado "function definitions" que é uma spec ES6 conforme mostra documentação (https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Functions/Parametros_Predefinidos).

Por isso no momento de realizar o "minify" do projeto o webpack do react detecta isso e ocorre o erro por questões de compatibilidade em navegadores mais antigos. vide documentação do create-react-app: (https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify)

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.