npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

validations-br

v1.4.0

Published

A validator to BR informations

Downloads

33,505

Readme

Leia isso em outras línguas: English

npm Coverage Status License

Visão geral

Validations BR é um cinto de ferramentas de funções para validar documentos padrões no Brasil e mais.

Instalação

Com npm:

npm install validations-br

Com yarn:

yarn add validations-br

Como usar

useValidationsBR

Parâmetros

| Chave | Tipo | Descrição | | :---- | :--------------------------------------------------: | --------------------------------: | | type | cnpj \| cpf \| cep \| email \| pis \| phone \| uf | Tipo de dados que serão validados | | value | string | Valor que será validado |

import { useValidationsBR } from 'validations-br';
// const { useValidationsBR } = require('validations-br');

const cnpj = '09.015.844/0001-80';
const isValid = useValidationsBR('cnpj', cnpj);

Validar CNPJ

import { validateCNPJ } from 'validations-br';
// const { validateCNPJ } = require('validations-br');


const cnpj = '09.015.844/0001-80';
const isValid = validateCNPJ(cnpj);

Validar CPF

import { validateCPF } from 'validations-br';
// const { validateCPF } = require('validations-br');

const cpf = '370.785.180-04';
const isValid = validateCPF(cpf);

Validar Inscrição Estadual

import { validateIE } from 'validations-br';
// const { validateIE } = require('validations-br');

const ie = '535.371.880.779';
const isValid = validateIE(ie, 'sp');

Validar PIS/PASEP

import { validatePIS } from 'validations-br';
// const { validatePIS } = require('validations-br');

const pis = '833.28281.34-7';
const isValid = validatePIS(pis);

Validar CNH

import { validateCNH } from 'validations-br';
// const { validateCNH } = require('validations-br');

const cnh = '134621966-24';
const isValid = validateCNH(cnh);

Validar Telefone

import { validatePhone } from 'validations-br';
// const { validatePhone } = require('validations-br');

const phone = '(14) 99767-9472';
const isValid = validatePhone(phone);

Validar CEP

import { validateCEP } from 'validations-br';
// const { validateCEP } = require('validations-br');

const cep = '17280-000';
const isValid = validateCEP(cep);

Validar UF

import { validateUF } from 'validations-br';
// const { validateUF } = require('validations-br');

const uf = 'SP';
const isValid = validateUF(uf);

Bônus

Validar E-mail

import { validateEmail } from 'validations-br';
// const { validateEmail } = require('validations-br');

const email = '[email protected]';
const isValid = validateEmail(email);

Integrações

Com Yup

import { validateCNPJ } from "validations-br";
import * as Yup from "yup";

try {
  const schema = Yup.string().test(
    "is-cnpj",
    "CNPJ is not valid",
    (value) => validateCNPJ(value)
  );
  
  await schema.validate(cnpj);
} catch(err) {
  console.log(err.message);
}

Com Joi

import { validateCNPJ } from "validations-br";
import Joi from "joi";

try {
  const schema = Joi.string().custom(validateCNPJ, "Validate CNPJ");

  const { value } = schema.validate(cnpj);

  if (!value) {
    throw Error("CNPJ is not valid");
  }
} catch(err) {
  console.log(err.message);
}

Como contribuir

Fique a vontade para contribuir com o projeto. Nós só pedimos para que:

  • Dê fork (https://github.com/reactivando/validations-br/fork)
  • Crie sua branch da feature/fix (git checkout -b feature/fooBar)
  • Escreva os testes para a nova feature ou do bug fix resolvido
  • Faça o commit das mudanças (git commit -am 'feat: add some fooBar')
  • Siga os padrões de commit conventional-changelog descritos em conventional-conventions
  • Dê push dá branch para seu repositório (git push origin feature/fooBar)
  • Tenha certeza que os testes passaram antes de abrir a pull-request (Use: $ yarn test or $ npm run test)
  • Crie uma nova Pull Request

Autores

Licença

MIT © Reactivando