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

buildRegexFromDictfunction

A regular expression matching any key of a dictionary as a whole word, longest first. Words match in any alphabet, so québec is found at the start of a string and al is not found inside Montréal.

Import it

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

Definition

function buildRegexFromDict(dict: Record<string, string>, capture?: boolean): RegExp

Parameters

NameTypeDescription
dictRecord<string, string>

The dictionary whose keys are matched.

capture (optional)boolean

Whether to wrap the alternatives in a capturing group; default true.

Returns

RegExp

The expression, case-insensitive.

Examples

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

console.log(buildRegexFromDict({ street: "St", avenue: "Ave" }).test("avenue"));
// → true
true

What it prints (run when this page was built)

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