Node ViaCep
A wrapper to work with the ViaCep Web API.
Browser Support
This library relies on Fetch API. And this API is supported in the following browsers.
39+ ✔ | 42+ ✔ | 29+ ✔ | 10.1+ ✔ | Nope ✘ |
Dependencies
This library depends on fetch to make requests to the Spotify Web API. For environments that don't support fetch, you'll need to provide a polyfill to browser or polyfill to Node.
more info on how to use node-fech.
Installation
$ npm install node-viacep --save
How to use
ES6
// to import a specific method; const viacep = type: 'json'
CommonJS
const ViaCep = default; const viacep = type: 'json'
UMD in Browser
<!-- to import non-minified version --> <!-- to import minified version -->
After that the library will be available to the Global as ViaCep
. Follow an example:
; globalfetch = ; const viacep = type: 'json' const address = viacepzipCod; address ;
Types and returns
The types to use in constructor
JSON
//use in zipCod and address methods const viacep = type: 'json' //return cep: '29010-250' logradouro: 'Rua Alberto de Oliveira Santos' complemento: '' bairro: 'Centro' localidade: 'Vitória' uf: 'ES' unidade: '' ibge: '3205309' gia: ''
XML
//use in zipCod and address methodsconst viacep = type: 'xml' //return<?xml version="1.0" encoding="UTF-8"?><xmlcep> <cep>29010-250</cep> <logradouro>Rua Alberto de Oliveira Santos</logradouro> <complemento></complemento> <bairro>Centro</bairro> <localidade>Vitória</localidade> <uf>ES</uf> <unidade></unidade> <ibge>3205309</ibge> <gia></gia></xmlcep>
PIPED
//just use in zipCod methods const viacep = type: 'piped' //returncep:29010-250|logradouro:Rua Alberto de Oliveira Santos|complemento:|bairro:Centro|localidade:Vitória|uf:ES|unidade:|ibge:3205309|gia:
QUERTY
//just use in zipCod methodsconst viacep = type: 'json' //returncep=29010-250&logradouro=Rua+Alberto+de+Oliveira+Santos&complemento=&bairro=Centro&localidade=Vit%C3%B3ria&uf=ES&unidade=&ibge=3205309&gia=
Methods
zipCod methods
Follow the methods that the library provides.
zipCod.getZip(query)
Search for informations about zipcode with provided query. Test in ViaCep Api.
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
this method returns the type specified in the constructor
viacepzipCod ;
zipCod.getJson(query)
Search for informations about zipcode with provided query. Test in ViaCep Api.
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
this method returns a json
viacepzipCod ;
zipCod.getXml(query)
Search for informations about zipcode with provided query. Test in ViaCep Api.
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
this method returns an xml
viacepzipCod ;
zipCod.getPiped(query)
Search for informations about zipcode with provided query. Test in ViaCep Api.
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
this method returns a piped
viacepzipCod ;
zipCod.getQuerty(query)
Search for informations about zipcode with provided query. Test in ViaCep web API.
Arguments
Argument | Type | Options |
---|---|---|
query |
string | 'Any search query' |
Example
this method returns a querty
viacepzipCod ;
address methods
address.getJson(ids)
Search for informations about some address with all id's. Test in ViaCep web APi.
Arguments
Argument | Type | Options |
---|---|---|
ids |
Array of strings | ['UF', 'city', 'street'] |
Example
this method returns a json
viacepaddress ;
address.getXml(ids)
Search for informations about some address with all id's. Test in ViaCep web APi..
Arguments
Argument | Type | Options |
---|---|---|
ids |
Array of strings | ['UF', 'city', 'street'] |
Example
this method returns an xml
viacepaddress ;
Contributing
Please read CONTRIBUTING.md file for details
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
Adriano Reis |
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details