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

How-to

Look up postal regions

Distinguish syntax, known data and region membership.

Read known regions

import { getStateFromZip,getProvinceFromPostalCode } from "@johnmorrisdotca/address-plus";
import { getPrefectureFromJapanesePostalCode } from "@johnmorrisdotca/address-plus/jp";
import { getStatesForAustralianPostcode } from "@johnmorrisdotca/address-plus/au";
console.log(getStateFromZip("98101"),getProvinceFromPostalCode("M5H 2N2"),getPrefectureFromJapanesePostalCode("530-0001"));
console.log(getStatesForAustralianPostcode("2618"));
WA ON 27
[ 'ACT', 'NSW' ]

A code may be syntactically valid, present in stored data, associated with more than one region, or unknown to the table. Use plural lookups where the native data represents cross-border delivery. Do not replace an ambiguous or absent result with a guessed region. Postal-prefix tables are a lookup aid rather than a list of every delivery point.

Inspect a country postcode

import { parseUKPostcode } from "@johnmorrisdotca/address-plus/gb";
import { parseGermanPostcode } from "@johnmorrisdotca/address-plus/de";
import { parseFrenchPostcode } from "@johnmorrisdotca/address-plus/fr";
console.log(parseUKPostcode("ec1a1bb"),parseGermanPostcode("10115"),parseFrenchPostcode("75002"));
{
  postcode: 'EC1A 1BB',
  outward: 'EC1A',
  inward: '1BB',
  area: 'EC',
  district: 'EC1A',
  sector: 'EC1A 1',
  country: 'GB',
  nation: 'ENG'
} { postcode: '10115', state: 'BE', known: true } {
  postcode: '75002',
  place: '75',
  country: 'FR',
  known: true,
  department: '75'
}

Normalization and known-data checks remain country-specific. Preserve leading zeros in strings; a postal code is not a number. The original postal reference includes format standards, validation fields and lookup tables. Public reference pages state each function’s exact null/undefined behavior.

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