1.0.7 • Published 18 days ago

api-estadosdobrasil v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
18 days ago

API - Estados do Brasil

The aim is to assist in querying Brazilian states and their cities, whether for use in user registration forms or even for filtering data in tracking tables or similar generic tasks.

We intentionally keep it simple by not providing information such as ZIP codes, street names, or neighborhood names.

To Install

Install the package api-estadosdobrasil in your project.

npm install api-estadosdobrasil

yarn add api-estadosdobrasil

bun add api-estadosdobrasil

How to consume?

There are several ways you can consume this API. You can simply:

Install the dependency and import Brasil, then assign it to a variable in your project.

import Brasil from 'api-estadosdobrasil'

const myEstados = Brasil.estados // To get all state information
const myCidades = Brasil.cidades // To get all city information

And how do I specifically get information about the city of Campinas, located in the interior of São Paulo, if I want to consume it?

import Brasil from 'api-estadosdobrasil'

const Campinas = Brasil.cidades.siglaEstado['SP'].nome['Campinas']

To consume only the name of the state of São Paulo:

import Brasil from 'api-estadosdobrasil'

const SP = Brasil.estados.id['SP'].nome

Of course, you can filter and customize this according to your preferences.

Another way is to fetch directly from the route or from the repository file.

  1. Fetch from the route and consume from there.
    fetch("https://api.github.com/users/Yagasaki7K")
        .then(response => response.json())
        .then(data => {
            setDataAPI(data) // If you're using a State of React for example.
            let data = JSON.stringify(data) // If you're using a variable.
        });

2.1 Fetch directly from the file in the repository - less recommended.

    fetch("https://github.com/Yagasaki7K/api-estadosdobrasil/blob/main/database.json")
        .then(response => response.text())
        .then(data => {
            setDataAPI(data) // If you're using a State of React for example.
            let data = JSON.stringify(data) // If you're using a variable.
        });

How to Contribute?

If you have ideas, you can contribute to the repository on GitHub, following the basic concepts of a pull request - we don't have a specific template for this.

Tests

bun test v1.1.4 (fbe2fe0c)

index.test.ts:
✓ Brasil object should be imported correctly [1.04ms]
✓ Should have states in the list of states [0.03ms]
✓ Should have cities in the list of cities [0.03ms]
✓ Campinas should be in the list of cities of São Paulo [1.20ms]
✓ São Paulo state should be in the list of states [0.03ms]

5 pass
1.0.7

18 days ago

1.0.5

18 days ago

1.0.6

18 days ago

1.0.20

18 days ago

1.0.21

18 days ago

1.0.2

18 days ago

1.0.1

18 days ago

1.0.0

18 days ago