Skip to content

Latest commit

 

History

History
71 lines (62 loc) · 1.74 KB

README.md

File metadata and controls

71 lines (62 loc) · 1.74 KB

Region Identifier

Utility module that provides an easy way to identify the region of the country depending on the postal code, brings a set of determined regions for some of the countries and if it doesn't find a match uses google geolocation API to get the region.

Relevant links:

Predefined Regions

  • AUT
  • BEL
  • CAN
  • CHE
  • DEU
  • ESP
  • FIN
  • FRA
  • GBR
  • ITA
  • MEX
  • NLD
  • RUS
  • SWE
  • USA

Test

$ npm test

License

This module was built using adapted information from http://download.geonames.org/ that's registered under the CC BY 3.0 as well as this module. Link to more information about CC BY 3.0 http://creativecommons.org/licenses/by/3.0/.

Usage

Basic:

const { RegionIdentifier } = requrie('regionIdentifier');
const identifier = new RegionIdentifier('<GOOGLE API KEY>');

Get region:

//Using country name
identifier.get('Deutschland', '6578')
    .then(([region, googleUsed])) => {
        console.log(region); // null DE-TH
    }
    .catch((err) => {
        console.error(err);
    });

//using ISO3 code
identifier.get('DEU', '6578')
    .then(([region, googleUsed])) => {
        console.log(region); // null DE-TH
    }
    .catch((err) => {
        console.error(err);
    });

//using ISO2 code
identifier.get('DE', '6578')
    .then(([region, googleUsed])) => {
        console.log(region); // null DE-TH
    }
    .catch((err) => {
        console.error(err);
    });