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

rastreio-correios

v1.1.7

Published

Biblioteca que permite rastrear objetos dos correios do Brasil

Downloads

48

Readme

📦 Rastreio Correios Brasil

Build Status Lint Status release-it

Rastreio correios é uma biblioteca que permite rastrear encomendas dos correios do Brasil

Conteúdo

Funcionalidades

  • Múltiplos serviços de rastreio (Consumimos 2 APIs)
  • Foco em performece (Buscamos a API que retorna mais rápido)
  • Padronização dos retornos das APIs
  • Possibilidade de rastrear mais de 1 encomenda

Instalando

npm i rastreio-correios

Como utilizar

const { rastrear } = require('rastreio-correios');

async myFn(){
  try{
    const result = await rastrear(['XX000000000BR', 'YY000000000BR']);

    // Também é possível passar uma string
    // await rastrear('XX000000000BR');

    console.log(result);
  } catch(error){
    console.log(error);
  }
}

myFn();

Utilizando o ES6

import { rastrear } from 'rastreio-correios';
...

Retorno dos dados

Os dados são sempre retornados em array (mesmo que seja passado apenas 1 código de rastreio);

RastreioResult {
  sucesso: boolean; // sucesso no rastreio
  rastreio: string; // código de rastreio
  responseTime: number; // tempo de resposta em ms
  mensagem?: string; // se houver erro, aqui estará a mensagem
  entregue?: boolean; // se o objeto foi entregue
  // array de eventos do rastreio
  type?: string; // tipo do pacote, por exemplo: PAC, SEDEX, etc.
  eventos?: {
    status: string; // status do evento
    data: string; // data do evento
    hora: string; // hora do evento
    origem?: string; // origem do evento (se existir)
    destino?: string; // destino do evento (se existir)
    local?: string; // local do evento (se existir)
  }[];
}

Validação

A lib possui um validador do formato do código de rastreio, quando o código informado não está de acordo com o padrão dos correios é retornado uma mansagem de erro:

const { rastrear } = require('rastreio-correios');

async myFn(){
  try{
    const result = await rastrear('XXA00000000BR');
    console.log(result);
    // {
    //   sucesso: false,
    //   rastreio: 'XXA00000000BR',
    //   mensagem: 'Código de rastreio inválido',
    //   responseTime: 0
    // }
  } catch(error){
    console.log(error);
  }
}

myFn();

Autor

| @fernandonetom | | :---: |