Skip to content

Identify the region code ISO 3166-2 from a country and zip code.

Notifications You must be signed in to change notification settings

parcelLab/regionIdentifier

Repository files navigation

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);
    });

About

Identify the region code ISO 3166-2 from a country and zip code.

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published