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 · Japanese addresses

ValidationOptionstype

Options for the validators: which parts an address must have, which kinds are allowed, and whether a postal code that does not match its region is an error.

Import it

import type { ValidationOptions } from "@johnmorrisdotca/address-plus/jp";

Also exported from: @johnmorrisdotca/address-plus/au, @johnmorrisdotca/address-plus/gb, @johnmorrisdotca/address-plus/de, @johnmorrisdotca/address-plus/fr, @johnmorrisdotca/address-plus

Definition

interface ValidationOptions {
    requireStreetNumber?: boolean;
    requireStreetName?: boolean;
    requireCity?: boolean;
    requireState?: boolean;
    requirePostalCode?: boolean;
    allowPOBox?: boolean;
    allowRuralRoute?: boolean;
    allowGeneralDelivery?: boolean;
    strictPostalValidation?: boolean;
    country?: ParseOptions["country"];
    countries?: readonly import("./country-module").CountryModule[];
}

Members

NameTypeDescription
requireStreetNumber (optional)boolean | undefined
requireStreetName (optional)boolean | undefined
requireCity (optional)boolean | undefined
requireState (optional)boolean | undefined
requirePostalCode (optional)boolean | undefined
allowPOBox (optional)boolean | undefined
allowRuralRoute (optional)boolean | undefined
allowGeneralDelivery (optional)boolean | undefined
strictPostalValidation (optional)boolean | undefined
country (optional)"CA" | "US" | "JP" | "AU" | "GB" | "GY" | "IM" | "JE" | FrenchPostalCountry | "DE" | "GP" | "MQ" | "GF" | "RE" | "YT" | "auto" | undefined
countries (optional)readonly CountryModule[] | undefined

Examples

import { validateAddress } from "@johnmorrisdotca/address-plus";
import type { ValidationOptions } from "@johnmorrisdotca/address-plus/jp";

console.log(validateAddress("123 Main St", { requirePostalCode: true }).errors.map((error) => error.code));
// → ["MISSING_POSTAL_CODE"]
[ 'MISSING_POSTAL_CODE' ]

What it prints (run when this page was built)

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