Skip to content

feat: adiciona função findAddress para busca por endereço#272

Open
mateus-araujo wants to merge 10 commits into
BrasilAPI:masterfrom
mateus-araujo:feature/find-address
Open

feat: adiciona função findAddress para busca por endereço#272
mateus-araujo wants to merge 10 commits into
BrasilAPI:masterfrom
mateus-araujo:feature/find-address

Conversation

@mateus-araujo
Copy link
Copy Markdown

Descrição

Esta PR adiciona a função findAddress que permite buscar endereços brasileiros utilizando estado, cidade e rua, não apenas por CEP.

A implementação foi baseada na biblioteca cep-address-finder do próprio autor, trazendo a funcionalidade para o cep-promise com suporte a múltiplos provedores.

Principais mudanças

  • Nova função findAddress: Permite buscar endereços informando estado, cidade e rua
  • 🔍 Múltiplos provedores: Funciona com concorrência entre provedores (padrão já utilizado na função cep)
  • 🎯 Seleção inteligente: Seleciona o endereço correto baseado no número e/ou bairro informado
  • Testes: 12 novos testes unitários seguindo os padrões do projeto
  • 📝 Documentação: README.md e definições TypeScript atualizadas

Exemplo de uso

import { findAddress } from 'cep-promise'
// Busca básica
findAddress({
  state: 'SP',
  city: 'São Paulo',
  street: 'Rua Caiubí'
}).then(console.log)

// Com número e bairro para seleção mais precisa
findAddress({
  state: 'SP',
  city: 'São Paulo',
  street: 'Rua Caiubí',
  number: '123',
  neighborhood: 'Perdizes'
}).then(console.log)

// Especificando provedores
findAddress({
  state: 'SP',
  city: 'São Paulo',
  street: 'Rua Caiubí',
  providers: ['viacep']
}).then(console.log)

Commits

Checklist

  • Todos os testes passando (63 testes)
  • Lint passando (StandardJS)
  • Build funcionando
  • Cobertura de testes > 95%

- normalizeString: normalize strings for URLs
- compareStrings: compare strings with normalization
- convertViaCEPAddress: convert ViaCEP format to library format
- isNumberAtComplementPattern: check number patterns in complements
- selectAddressFromList: select best address match from list
- Add fetchViaCepAddressSearch function
- Update services index with getAvailableAddressSearchServices
- Supports search by state/city/street
- Export findAddress from main entry point
- Supports multiple providers (concurrent queries)
- Validation for state, city, street
- Provider selection via providers parameter
- Returns addresses list and selectedAddress
- 12 unit tests following project patterns
- Test fixtures for address search
- Cover validation, success, and error cases
- Add findAddress examples to README.md
- Add TypeScript definitions for findAddress
- Document providers parameter
- Rebuild with findAddress function
- Update minified versions
- Update package-lock.json
- Replace nested ternaries with if/else statements
- Extract helper functions for better organization
- Add comments to explain the logic
- Make the code easier to understand and maintain
Comment thread package.json Outdated
@mateus-araujo mateus-araujo force-pushed the feature/find-address branch from 027c571 to 733819d Compare May 1, 2026 21:50
@mateus-araujo mateus-araujo requested a review from wellwelwel May 1, 2026 21:53
- normalizeString: accent removal, special chars, empty/null handling
- compareStrings: exact match, partial match, no match
- convertViaCEPAddress: format conversion
- isNumberAtComplementPattern: pattern matching
Copy link
Copy Markdown
Contributor

@wellwelwel wellwelwel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opá! Eu não faço parte do repositório, mas gostei da ideia/feature 😅


Vi que as mudanças não são tão grandes quanto parecem:

@mateus-araujo, tem algum motivo do porque modificar o package-lock.json junto nesse PR? Se for por questão de dependências desatualizadas, eu recomendaria fazer isso em um PR separado, mas vale esperar pelos mantenedores 🙋🏻‍♂️

@mateus-araujo mateus-araujo force-pushed the feature/find-address branch 2 times, most recently from 712baf1 to adb71ad Compare May 1, 2026 22:19
- Simplify isNumberAtComplementPattern with better regex
- Fix selectAddressFromList filtering logic
- Add comprehensive tests for all code paths
- Cover even/odd lado selection, pattern matching, fallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants