https://github.com/holyshared/zip-code-jp
Address search from zip code for japanese
https://github.com/holyshared/zip-code-jp
csv jp nodejs zip-code
Last synced: about 1 month ago
JSON representation
Address search from zip code for japanese
- Host: GitHub
- URL: https://github.com/holyshared/zip-code-jp
- Owner: holyshared
- License: mit
- Created: 2015-11-18T10:49:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-24T07:10:48.000Z (almost 9 years ago)
- Last Synced: 2025-04-21T17:58:38.327Z (about 2 months ago)
- Topics: csv, jp, nodejs, zip-code
- Language: JavaScript
- Homepage:
- Size: 3.83 MB
- Stars: 10
- Watchers: 0
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zip-code-jp
郵便番号から、住所を検索できるモジュールです。
郵便番号データのソースは[郵便事業株式会社(旧郵政省)](http://www.post.japanpost.jp/zipcode/download.html)提供のデータを使用しています。[postal-code-jp](https://www.npmjs.com/package/postal-code-jp)を使用している場合は、代わりに[zip-code-jp](https://www.npmjs.com/package/zip-code-jp)を使用してください。
[](https://badge.fury.io/js/zip-code-jp)
[](https://travis-ci.org/holyshared/zip-code-jp)
[](https://codecov.io/github/holyshared/zip-code-jp?branch=master)
[](https://david-dm.org/holyshared/zip-code-jp)## インストール方法
下記のコマンドでインストールできます。
npm install zip-code-jp
## 基本的な使用方法
郵便番号から、住所の情報を返します。
```js
import AddressResolver from 'zip-code-jp';const resolver = new AddressResolver();
resolver.find('0010933').then((results) => {
console.log(results[0].prefecture); // 都道府県
console.log(results[0].city); // 市区町村名
console.log(results[0].area); // 町域名
console.log(results[0].street); // 番地
});
```## 検索結果のキャッシュ
キャッシュに利用するアダプタを変えることで、独自のキャッシュ処理に切り替えることができます。
デフォルトでは、**MemoryCacheAdapter**を使用して、メモリにキャッシュします。```js
import AddressResolver from 'zip-code-jp';
import { cache } from 'zip-code-jp';const memoryAdapter = new cache.MemoryCacheAdapter();
const resolver = new AddressResolver(memoryAdapter);resolver.find('0010933').then((results) => {
console.log(results[0].prefecture); // 都道府県
console.log(results[0].city); // 市区町村名
console.log(results[0].area); // 町域名
console.log(results[0].street); // 番地
});
```## 独自アダプタの実装
**CacheAdapter**をサブクラス化して、独自のアダプタを使用できるようになります。
下記のメソッドを実装する必要があります。* find(prefix) - 郵便番号の頭3桁を引数に取り、該当する辞書を返します。
* store(prefix, store) - 郵便番号の頭3桁と、辞書を受け取り、キャッシュします。```js
import AddressResolver from 'zip-code-jp';
import { cache } from 'zip-code-jp';class CustomAdapter extends cache.CacheAdapter {
constructor() {
super();
}/**
* Search the dictionary from the cache
*
* @param {string} prefix
* @return Promise
*/
find(prefix) {
}/**
* Cache the dictionary
*
* @param {string} prefix
* @param {Object} dict
* @return Promise
*/
store(prefix, dict) {
}
}const resolver = new AddressResolver(new CustomAdapter());
resolver.find('0010933').then((results) => {
console.log(results[0].prefecture); // 都道府県
console.log(results[0].city); // 市区町村名
console.log(results[0].area); // 町域名
console.log(results[0].street); // 番地
});
```## 辞書ファイルの更新
npm run index
## テストの実行
次のコマンドで、テストを実行できます。
npm install
npm test