# easy-ja-postal-code-search-address

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

Latest version **1.0.4** (published 2023-03-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install easy-ja-postal-code-search-address
pnpm add easy-ja-postal-code-search-address
yarn add easy-ja-postal-code-search-address
bun add easy-ja-postal-code-search-address
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2023-03-31 |
| First published | 2023-03-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | go.nishiduka.1985@gmail.com |
| Maintainers | underground0930 |
| Keywords | zip, postal code, japanese, javascript |

## Links

- npm: https://www.npmjs.com/package/easy-ja-postal-code-search-address
- Repository: https://github.com/underground0930/easy-ja-postal-code-search-address
- Homepage: https://github.com/underground0930/easy-ja-postal-code-search-address#readme.md
- Issues: https://github.com/underground0930/easy-ja-postal-code-search-address/issues
- npm.io page: https://npm.io/package/easy-ja-postal-code-search-address

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2023-03-31
- 1.0.3 — 2023-03-31
- 1.0.2 — 2023-03-31
- 1.0.1 — 2023-03-31
- 1.0.0 — 2023-03-31

## README

# easy-ja-postal-code-search-address [![npm version](https://img.shields.io/npm/v/easy-ja-postal-code-search-address.svg?style=flat)](https://www.npmjs.com/package/easy-ja-postal-code-search-address)

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

**<a href="https://www.npmjs.com/package/easy-ja-postal-code-generate-json" target="_blank">easy-ja-postal-code-generate-json</a>**<br>
で生成した json ファイルが必要になります。

# Features

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

# Requirement

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

# Usage

```bash
# install
npm i easy-ja-postal-code-search-address

```

```javascript
import { SearchAddress } from 'easy-ja-postal-code-search-address'
```

# Examples

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

# Initialize

```javascript
const afpc = new SearchAddress({
  baseUrl: '/json/zip/',
  fallback: () => alert('初期化に失敗しました'),
})
```

| name     | 説明                                                                                         | require |
| -------- | -------------------------------------------------------------------------------------------- | ------- |
| baseUrl  | json が入っているディレクトリ                                                                | ●       |
| fallback | 初期化に失敗した時の処理を書く,ディレクトリの設定ミスで、index.json が読み込めなかった時など |         |

# Methods

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

# Return value of hoge method

```typescript

// 検索結果のデータ型
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 // 入力された頭３桁はindexファイルに存在しない
    notFound?: true // 入力された郵便番号から住所は見つからなかった
  }
}

```

# Author

- https://twitter.com/resistance_gowy
- go.nishiduka.1985@gmail.com

# License

"easy-ja-postal-code-search-address" is under [MIT license](https://en.wikipedia.org/wiki/MIT_License).

---
_Source: https://npm.io/package/easy-ja-postal-code-search-address · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
