本文へ移動

address-plusアドレスプラス

住所を端末の中で解析・確認・整形・比較し、国のモジュールや任意のフォームの入力欄を使えます。

address-plusは、parse-addressの使い方を広げ、型付きの結果、確認、書式、国のモジュールを加えます。 名前について(英語)

目次

リファレンス · 解析・書式・共通の型

parseLocation関数

リファレンスの説明と例は英語です。見出しと目次は日本語です。

Parses a US, Canadian or Japanese address into its parts. The country is detected from the text (a state, a province, a postal code, Japanese script or romaji designators) unless options.country names it. A Japanese address fills its own fields (prefecture, municipality, town, chome, ban, go) and the shared ones that stand for them. Australia and the United Kingdom are read too when their modules are passed in options.countries (australia from /au, unitedKingdom from /gb): options.country picks one, or each module's own detection decides, before the US, Canada and Japan are tried.

インポート

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

定義

function parseLocation(address: string, options?: ParseOptions): ParsedAddress | null

引数

名前型説明
addressstring

The address as one string; commas, line breaks and full-width characters are all read.

options (省略可)ParseOptions

How to parse: the country, strict postal codes, snake_case keys and the rest (see ParseOptions).

戻り値

ParsedAddress | null

The parts found, or null when the text is empty or holds nothing that can be read as an address. A part that is not in the address is absent from the result, never an empty string.

例

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

console.log(parseLocation("1600 Pennsylvania Ave NW, Washington, DC 20500"));
// → {"number":"1600","street":"Pennsylvania","type":"Ave","suffix":"NW","city":"Washington","state":"DC","zip":"20500","zipValid":true,"country":"US"}
{
  number: '1600',
  street: 'Pennsylvania',
  type: 'Ave',
  suffix: 'NW',
  city: 'Washington',
  state: 'DC',
  zip: '20500',
  zipValid: true,
  country: 'US'
}

出力(このページを作ったときに実行した結果)

ソースを見るGitHub で編集@johnmorrisdotca/address-plus 1.7.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。