Skip to the content

address-plusアドレスプラス

Parse, validate, format and compare addresses locally, add country modules and mount an optional native form field.

address-plus extends the parse-address style with typed results, validation, formatting and country modules. About the name

Contents

Reference · /br

parseBrazilianAddressfunction

Parses an address in Brazil into the parts the Correios lay out: who it is care of (careOf), the street as written with its type (street: Avenida Paulista, R. Augusta), its number (number: 1578, S/N), the complement (secUnitType and secUnitNum: Apto 45, Sala 12; building for a bloco or a torre; floorType Andar and floor), the bairro in locality, the city in city, the CEP in zip (written 01310-200) and the state's code in state (SP), as written or from the CEP. The number follows the street after a comma or not, and the bairro after a hyphen or a comma.

Import it

import { parseBrazilianAddress } from "@johnmorrisdotca/address-plus/br";

Definition

function parseBrazilianAddress(text: string, options?: ParseOptions): ParsedAddress | null

Parameters

NameTypeDescription
textstring

The address as one string; commas and line breaks both separate its parts.

options (optional)ParseOptions

useSnakeCase gives snake_case keys; the other options are not used.

Returns

ParsedAddress | null

The parts found, with country BR, or null when the text is empty or holds nothing that makes it an address.

Examples

import { parseBrazilianAddress } from "@johnmorrisdotca/address-plus/br";

console.log(parseBrazilianAddress("Avenida Paulista, 1578 - Bela Vista, São Paulo - SP, 01310-200"));
// → {"number":"1578","street":"Avenida Paulista","locality":"Bela Vista","city":"São Paulo","state":"SP","zip":"01310-200","zipValid":true,"country":"BR"}
{
  number: '1578',
  street: 'Avenida Paulista',
  locality: 'Bela Vista',
  city: 'São Paulo',
  state: 'SP',
  zip: '01310-200',
  zipValid: true,
  country: 'BR'
}

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/address-plus 1.10.2.