1.0.4 • Published 1 year ago

easy-ja-postal-code-search-address v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

easy-ja-postal-code-search-address npm version

郵便番号から住所を簡単に検索するためのヘルパークラス

easy-ja-postal-code-generate-json で生成した json ファイルが必要になります。

Features

  • 「easy-ja-postal-code-generate-json」で生成した郵便番号の json ファイルデータから住所を郵便番号経由で検索します
  • json ファイルを扱いやすくするためのクラスです。
  • 郵便番号データは、全国だと膨大になるため、頭3桁ごとに json ファイルでまとめています。必要なファイルだけ読み込むためです。
  • 一度呼び出した json ファイルのデータはキャッシュします。

Requirement

  • easy-ja-postal-code-generate-json
  • Node.js v18.13.0

Usage

# install
npm i easy-ja-postal-code-search-address
import { SearchAddress } from 'easy-ja-postal-code-search-address'

Examples

サンプルファイルは examples フォルダをご覧ください

Initialize

const afpc = new SearchAddress({
  baseUrl: '/json/zip/',
  fallback: () => alert('初期化に失敗しました'),
})
name説明require
baseUrljson が入っているディレクトリ
fallback初期化に失敗した時の処理を書く,ディレクトリの設定ミスで、index.json が読み込めなかった時など

Methods

method説明
search({ zipInput }: { zipInput: string }): any郵便番号の文字列を入れると、それに応じた住所 or エラーを返却
afpc.fetchAbort() => voidjson の fetch を止めたい時に呼ぶ(React で Component の破棄する時など)

Return value of hoge method

// 検索結果のデータ型
type ZipData = {
  zip: string
  prefectures: string
  city: string
  other: string
}

// 成功したときの返却値
{
  address: ZipData
  error: null
}

// 失敗したときの返却値
{
  address: null
  error: {
    loading?: true // ローディング中
    notReady?: true // 準備に失敗した
    inValid?: true // 入力値が不正
    noFirstThreeDigits?: true // 入力された頭3桁はindexファイルに存在しない
    notFound?: true // 入力された郵便番号から住所は見つからなかった
  }
}

Author

License

"easy-ja-postal-code-search-address" is under MIT license.

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago