https://www.npmjs.com/package/ken-all
Ken All は、郵便番号で住所を検索できる npm パッケージです。
import KenAll from 'ken-all';
// [['東京都', '千代田区', '大手町']];
KenAll('1000004').then(res => console.log(res));
$ npm install ken-all
もしくは
$ yarn add ken-all
import
したKenAll
に、7桁半角数字の文字列を渡します。
import KenAll from 'ken-all';
// [['東京都', '千代田区', '大手町']];
KenAll('1000004').then(res => console.log(res));
返り値は、以下の値を持つpromise
オブジェクトです。
[
['都道府県', '市区町村', '町域'],
['都道府県', '市区町村', '町域'],
// ...
]
// [["愛知県", "弥富市", ""], ["三重県", "桑名郡木曽岬町", ""]]
KenAll('4980000').then(res => console.log(res));
該当する住所がない場合は、空の配列を返します。
// []
KenAll('9009999').then(res => console.log(res));
型定義ファイルも同梱しているので、TypeScript アプリでも利用することが出来ます。
内部でfetch
を行っているので、fetch
を使えない環境ではポリフィルが必要になります。