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 · /nz

parseNewZealandAddressfunction

Parses an address in New Zealand into the parts NZ Post lays out: who it is care of (careOf), the unit (secUnitType and secUnitNum, from Unit 3 or the 3 of 3/45), the level (floorType and floor), the street's number (number: 45, 12A, 12-14) and its name as written (street: Dominion Road), the suburb in locality, the city in city, a PO Box, a Private Bag or a rural delivery (secUnitType RD and secUnitNum), the postcode in zip and the region's code in state (AUK), from the postcode. The city stands before the postcode.

Import it

import { parseNewZealandAddress } from "@johnmorrisdotca/address-plus/nz";

Definition

function parseNewZealandAddress(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 NZ, or null when the text is empty or holds nothing that makes it an address.

Examples

import { parseNewZealandAddress } from "@johnmorrisdotca/address-plus/nz";

console.log(parseNewZealandAddress("3/45 Dominion Road, Mount Eden, Auckland 1024"));
// → {"secUnitType":"Unit","secUnitNum":"3","number":"45","street":"Dominion Road","locality":"Mount Eden","city":"Auckland","state":"AUK","zip":"1024","zipValid":true,"country":"NZ"}
{
  secUnitType: 'Unit',
  secUnitNum: '3',
  number: '45',
  street: 'Dominion Road',
  locality: 'Mount Eden',
  city: 'Auckland',
  state: 'AUK',
  zip: '1024',
  zipValid: true,
  country: 'NZ'
}

What it prints (run when this page was built)

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