pix-utils-js
v1.0.8
Published
Um pacote para fornecer utilidades e validações para chaves pix.
Readme
💸 pix-utils-js
Uma pequena biblioteca que irá te ajudar a lidar com chaves pix
Instalação
Instale pix-utils-js com npm ou yarn
npm install pix-utils-js
yarn add pix-utils-jsDocumentação
Identifique uma chave pix
import { identify } from 'pix-utils-js'
const { pix, type } = identify({pix: '[email protected]'}) // {pix: '[email protected]', type: 'email'}| Função | Parametro | Retorno |
| :---------- | :--------- | :---------------------------------- |
| identify | input: {pix: string} | Pix { pix: string, type: 'email' \| 'cpf' \| 'cnpj' \| 'random' \|'phone' \| 'qrcode' } |
Validar uma chave pix
import { validate } from 'pix-utils-js'
console.log(validate({pix: '[email protected]'})) // true
console.log(validate({pix: 'test'})) // false
console.log(validate({pix: '[email protected]', type : 'cpf'})) // false
console.log(validate({pix: '00020126360014BR.GOV...', type : 'qrcode'})) // true| Função | Parametro | Retorno |
| :---------- | :--------- | :---------------------------------- |
| validate | input: {pix: string} | boolean |
Normalizar uma chave pix
import { normalize } from 'pix-utils-js'
console.log(normalize({pix: '000.000.000-00'})) // {pix: '00000000000', type: 'cpf'}
console.log(normalize({pix: '00.000.000/0000-00'})) // {pix: '00000000000000', type: 'cnpj'}
console.log(normalize({pix: '(11) 98888-8888'})) // {pix: '11988888888', type: 'phone'}
console.log(normalize({pix: '00020126360014BR.GOV...'})) // {pix: '00020126360014BR.GOV...', type: 'qrcode'}| Função | Parametro | Retorno |
| :---------- | :--------- | :---------------------------------- |
| normalize | input: {pix: string} | Pix { pix: string, type: 'email' \| 'cpf' \| 'cnpj' \| 'random' \|'phone' \| 'qrcode' } |
Rodando os testes
Para rodar os testes, rode o seguinte comando
npm run test