Reference · Parsing, formatting and shared types
COMMON_PARSER_PATTERNSconstant
Pattern builders the parsers share: a ZIP, a state or a postal code at the end of a text, and a city before a state. Each takes the source of a pattern wrapped in one pair of parentheses or anchors, which it strips.
Import it
import { COMMON_PARSER_PATTERNS } from "@johnmorrisdotca/address-plus";
Definition
const COMMON_PARSER_PATTERNS: { readonly ZIP_AT_END: (zipPattern: string) => RegExp; readonly STATE_AT_END: (statePattern: string) => RegExp; readonly CITY_STATE_PATTERN: (stateAbbrevPattern: string) => RegExp; readonly POSTAL_AT_END: (postalPattern: string) => RegExp; } = {
ZIP_AT_END: (zipPattern: string) => new RegExp(`\\s+(${zipPattern.slice(1, -1)})\\s*$`),
STATE_AT_END: (statePattern: string) => new RegExp(`\\s+(${statePattern.slice(1, -1)})\\s*$`, "i"),
CITY_STATE_PATTERN: (stateAbbrevPattern: string) => new RegExp(`^(.+?)\\s+(${stateAbbrevPattern.slice(1, -1)})\\s*$`, "i"),
POSTAL_AT_END: (postalPattern: string) => new RegExp(postalPattern + "$", "i"),
} as const
Members
| Name | Type | Description |
|---|---|---|
ZIP_AT_END | (zipPattern: string) => RegExp | |
STATE_AT_END | (statePattern: string) => RegExp | |
CITY_STATE_PATTERN | (stateAbbrevPattern: string) => RegExp | |
POSTAL_AT_END | (postalPattern: string) => RegExp |
Examples
import { COMMON_PARSER_PATTERNS } from "@johnmorrisdotca/address-plus";
console.log(COMMON_PARSER_PATTERNS.ZIP_AT_END("(\\d{5})").exec("Tacoma WA 98402")?.[1]);
// → "98402"98402What it prints (run when this page was built)