1.0.7 • Published 2 years ago

tw-address v1.0.7

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
2 years ago

tw-address

Get TW road list by open data API.

Install

npm i tw-address

Usage

const TWAddress = require('tw-address');

/**
 * Create new instance.
 * First argument is ROC year. Available values are 107, 108, 109, 110, optional, default value: CURRENT_ROC_YEAR
 * Second argument is API base url, optional, default: https://www.ris.gov.tw/rs-opendata/api/v1/datastore/ODRP049
 */
const twAddress = new TWAddress(110);

/**
 * To get road list.
 * First argument is county, required.
 * Second argument is town, required.
 * @type {Promise}
 */
twAddress.getRoadList('臺北市', '中正區')
  .then(roads => {
    /**
     * Return data type is {string[]}
     */
    roads.forEach((road) => {
      console.log(road);
    });
  });

/**
 * To get roads data.
 * First argument is county, optional.
 * Second argument is town, optional.
 * Third argument is page, optional, default: 1.
 * @type {Promise}
 */
twAddress.getAPI('臺北市', '中正區', 1)
  .then(resp => {
    /**
     * Response schema:
     * https://github.com/hqiasjehrlb/tw-address/blob/aaba0978da90f43e3af1855050546325fef2a448/lib/roadsAPI.js#L76
     */
    console.log(resp);
  });

/**
 * To get county list.
 * @type {string[]}
 */
const counties = TWAddress.getCountyList();

/**
 * To get town list.
 * Argument <county> is required.
 * @type {string[]}
 */
const towns = TWAddress.getTownList(county);

References

Taiwan District Data

Taiwan Roads Opendata Documentation

Taiwan Roads Opendata Information

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago