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

cep-promise-debug

v3.0.11

Published

Busca por CEP integrado diretamente aos serviços dos Correios e ViaCEP

Downloads

4

Readme

Features

  • Sempre atualizado em tempo-real por se conectar diretamente aos serviços dos Correios, ViaCEP e WideNet.
  • Possui alta disponibilidade por usar vários serviços como fallback.
  • Sempre retorna a resposta mais rápida por fazer as consultas de forma concorrente.
  • Sem limites de uso (rate limits) conhecidos.
  • Interface de Promise extremamente simples.
  • Suporte ao Node.js 4.x, 5.x, 6.x, 7.x, 8.x, 9.x, 10.x e @stable.
  • Suporte ao Node.js 0.10.x e 0.12.x até cep-promise versão 2.0.8.
  • 100% de code coverage com testes unitários e E2E.
  • Desenvolvido utilizando ES6.

Como utilizar

Teste e aprenda aqui.

Realizando uma consulta

Por ser multifornecedor, a biblioteca irá resolver a Promise com o fornecedor que mais rápido lhe responder.

import cep from 'cep-promise'

cep('05010000')
  .then(console.log)

  // {
  //   "cep":  "05010000",
  //   "state":  "SP",
  //   "city":  "São Paulo",
  //   "street":  "Rua Caiubí",
  //   "neighborhood":  "Perdizes",
  // }

Você também poderá passar o CEP como Inteiro

Em muitos sistemas o CEP é utilizado erroneamente como um Inteiro (e com isto cortando todos os zeros à esquerda). Caso este seja o seu caso, não há problema, pois a biblioteca irá preencher os caracteres faltantes na String, por exemplo:

import cep from 'cep-promise'

// enviando sem ter um zero à esquerda do CEP "05010000"
cep(5010000)
  .then(console.log)

  // {
  //   "cep":  "05010000",
  //   "state":  "SP",
  //   "city":  "São Paulo",
  //   "street":  "Rua Caiubí",
  //   "neighborhood":  "Perdizes",
  // }

Quando o CEP não é encontrado

Neste caso será retornado um "service_error" e por ser multifornecedor, a biblioteca irá rejeitar a Promise apenas quando tiver a resposta negativa de todos os fornecedores.

import cep from 'cep-promise'

cep('99999999')
  .catch(console.log)

  // {
  //     name: 'CepPromiseError',
  //     message: 'Todos os serviços de CEP retornaram erro.',
  //     type: 'service_error',
  //     errors: [{
  //       message: 'CEP NAO ENCONTRADO',
  //       service: 'correios'
  //     }, {
  //       message: 'CEP não encontrado na base do ViaCEP.',
  //       service: 'viacep'
  //     }]
  // }

Quando o CEP possui um formato inválido

Neste caso será retornado um "validation_error" e a biblioteca irá rejeitar imediatamente a Promise, sem chegar a consultar nenhum fornecedor.

import cep from 'cep-promise'

cep('123456789123456789')
  .catch(console.log)

  // {
  //     name: 'CepPromiseError',
  //     message: 'CEP deve conter exatamente 8 caracteres.',
  //     type: 'validation_error',
  //     errors: [{
  //       message: 'CEP informado possui mais do que 8 caracteres.',
  //       service: 'cep_validation'
  //     }]
  // }

Instalação

Browser usando CDN

<script src="https://cdn.jsdelivr.net/npm/cep-promise/dist/cep-promise.min.js"></script>

npm

$ npm install --save cep-promise

Bower

$ bower install --save cep-promise

yarn

$ yarn add cep-promise

Angular 2

import * as cep from 'cep-promise'

cep('05010000')
  .then(console.log)

Como contribuir

Leia nosso guia de contribuição aqui

Contribuidores

| @lucianopf | @MarcoWorms | @caio-ribeiro-pereira | @chrisbenseler | @luanmuniz | @AlbertoTrindade | |:-:|:-:|:-:|:-:|:-:|:-:| | @pedrro | @petronetto | @olegon | @jhonnymoreira | @claytonsilva | @thiamsantos | | @flyingluscas | @otaviopace | @vagnercardosoweb |

Autor

| @filipedeschamps | | :---: |