本文へ移動

address-plusアドレスプラス

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

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

目次

リファレンス · 日本の住所

JP_DESIGNATED_CITIES定数

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

The twenty designated cities (政令指定都市) as municipalities of their own. Geolonia lists only their wards, but addresses often name the city alone (大阪市, Sapporo), and the city has a JIS code of its own: its wards' codes with the last digit 0 (札幌市 01100).

インポート

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

ほかのエクスポート元: @johnmorrisdotca/address-plus

定義

const JP_DESIGNATED_CITIES: readonly JapaneseMunicipality[] = (() => {
    const wardsByCity = new Map<string, JapaneseMunicipality[]>();
    for (const municipality of JP_MUNICIPALITIES) {
        const ward = municipality.name.match(DESIGNATED_CITY_WARD);
        if (!ward)
            continue;
        const key = `${municipality.prefecture}${ward[1]}`;
        if (!wardsByCity.has(key))
            wardsByCity.set(key, []);
        wardsByCity.get(key)!.push(municipality);
    }
    return [...wardsByCity.values()].map((wards): JapaneseMunicipality => {
        const first = [...wards].sort((left, right) => left.code.localeCompare(right.code))[0];
        const lowest = Number(first.code);
        return {
            code: String(lowest - (lowest % 10)).padStart(5, "0"),
            kana: commonStart(wards.map((ward) => ward.kana)),
            name: first.name.match(DESIGNATED_CITY_WARD)![1],
            prefecture: first.prefecture,
            romaji: first.romaji.split(" ")[0],
        };
    });
})()

例

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

console.log(JP_DESIGNATED_CITIES.length);
// → 20
20

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

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

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