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 · German country module

germanyconstant

Germany's module, for parseLocation and validateAddress: pass it in countries, and an address that ends with Germany or Deutschland, or has a German street and its number and a postcode first on its last line, is read as German; country: "DE" reads any address as one.

Import it

import { germany } from "@johnmorrisdotca/address-plus/de";

Definition

const germany: CountryModule = {
    code: "DE",
    codes: ["DE"],
    name: "Germany",
    detect: looksGerman,
    parse: parseGermanAddress,
    validate: validateGermanAddress,
    format: (address) => formatDeutschePost(address),
    compare: compareGermanAddresses,
}

Members

NameTypeDescription
codestring
codesreadonly string[]
namestring
detect(address: string): boolean
parse(address: string, options?: ParseOptions): ParsedAddress | null
validate(address: ParsedAddress, options?: ValidationOptions): CountryValidation
format(address: ParsedAddress): FormattedAddress
compare(first: ParsedAddress, second: ParsedAddress): CountryComparison

Examples

import { parseLocation } from "@johnmorrisdotca/address-plus";
import { germany } from "@johnmorrisdotca/address-plus/de";

console.log(parseLocation("Hauptstraße 12a, 10115 Berlin", { countries: [germany] })?.number);
// → "12A"
12A

What it prints (run when this page was built)

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