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

CITY_PATTERNSconstant

Patterns for a city of one or more words at the end of a text, after a space, used where no comma marks it. A word is letters of any alphabet, with apostrophes and hyphens inside it.

Import it

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

Definition

const CITY_PATTERNS: { readonly BASIC_CITY: RegExp; readonly MULTI_WORD_CITY: RegExp; readonly SINGLE_WORD_CITY: RegExp; readonly TWO_WORD_CITY: RegExp; } = {
    BASIC_CITY: new RegExp(String.raw `\s+(${CITY_WORD}(?:\s+${CITY_WORD})?)$`, "u"),
    MULTI_WORD_CITY: new RegExp(String.raw `\s+(${CITY_WORD}(?: ${CITY_WORD})*?)(?:\s+[A-Z]{2,3})?\s*$`, "u"),
    SINGLE_WORD_CITY: new RegExp(String.raw `\s+(${CITY_WORD})$`, "u"),
    TWO_WORD_CITY: new RegExp(String.raw `\s+(${CITY_WORD}\s+${CITY_WORD})$`, "u"),
} as const

Members

NameTypeDescription
BASIC_CITYRegExp
MULTI_WORD_CITYRegExp
SINGLE_WORD_CITYRegExp
TWO_WORD_CITYRegExp

Examples

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

console.log(CITY_PATTERNS.SINGLE_WORD_CITY.exec("Pine St Tacoma")?.[1]);
// → "Tacoma"
Tacoma

What it prints (run when this page was built)

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