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 · Parsing, formatting and shared types

parseSecondaryUnitfunction

Takes a secondary unit (apartment, suite, floor and the rest) off a street line.

Import it

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

Definition

function parseSecondaryUnit(text: string): { unit: string | undefined; secUnitType: string | undefined; secUnitNum: string | undefined; remaining: string; }

Parameters

NameTypeDescription
textstring

The street line.

Returns

{ unit: string | undefined; secUnitType: string | undefined; secUnitNum: string | undefined; remaining: string; }

The unit as written, its designator in full and its number (each undefined when there is none), and the text that remains.

Examples

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

console.log(parseSecondaryUnit("123 Main St Apt 4"));
// → {"unit":"Apartment 4","secUnitType":"Apartment","secUnitNum":"4","remaining":"123 Main St"}
{
  unit: 'Apartment 4',
  secUnitType: 'Apartment',
  secUnitNum: '4',
  remaining: '123 Main St'
}

What it prints (run when this page was built)

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