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

How-to

Format native postal lines

Use country-specific formats after a successful parse.

Format two postal layouts

import { parseLocation,formatUSPS,formatCanadaPost } from "@johnmorrisdotca/address-plus";
const us=parseLocation("123 Main St Apt 4, New York, NY 10001");
const ca=parseLocation("100 Queen St W, Toronto, ON M5H 2N2");
if(!us||!ca) throw new Error("This example did not parse.");
console.log(formatUSPS(us).lines,formatCanadaPost(ca).lines);
[ '123 MAIN ST APT 4', 'NEW YORK NY 10001' ] [ '100 QUEEN ST W', 'TORONTO ON  M5H 2N2' ]

Formatters return structured lines and a single-line representation. Choose the native postal formatter rather than inventing one punctuation rule for every country. Options decide delivery/last lines, upper case or country lines where documented. Preserve unit, building, floor and country-specific number-extension fields through parsing.

Write Japanese markers

import { parseJapaneseAddress,formatJapanese,formatJapaneseEnglish } from "@johnmorrisdotca/address-plus/jp";
const address=parseJapaneseAddress("〒100-0005 東京都千代田区丸の内1-2-3");
if(!address) throw new Error("This example did not parse.");
console.log(formatJapanese(address,{blockStyle:"markers",multiline:false}),formatJapaneseEnglish(address,{includeCountry:false}));
〒100-0005 東京都千代田区丸の内1丁目2番3号 1-2-3 丸の内, Chiyoda-ku, Tokyo 100-0005

Japanese and Japanese-English formatting are separate choices. Formatting a parsed address does not repair an unknown municipality or prove delivery. The original format standards and Japanese formatting remain available.

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