https://github.com/parcellab/regionidentifier
Identify the region code ISO 3166-2 from a country and zip code.
https://github.com/parcellab/regionidentifier
team-architecture
Last synced: 9 months ago
JSON representation
Identify the region code ISO 3166-2 from a country and zip code.
- Host: GitHub
- URL: https://github.com/parcellab/regionidentifier
- Owner: parcelLab
- Created: 2016-05-30T08:13:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-08-01T07:02:16.000Z (over 2 years ago)
- Last Synced: 2024-04-14T12:19:43.323Z (over 1 year ago)
- Topics: team-architecture
- Language: JavaScript
- Homepage: https://parcellab.com
- Size: 2.47 MB
- Stars: 3
- Watchers: 16
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:*
* https://en.wikipedia.org/wiki/ISO_3166-2 — codes used for all the regions can be found here
* https://en.wikipedia.org/wiki/Category:Postal_codes_by_country - explanations of postal code structure per country
* https://download.geonames.org/export/zip/ - all the Geoname files for download (see below)
#### Predefined Regions
- AUT
- BEL
- CAN
- CHE
- DEU
- ESP
- FIN
- FRA
- GBR
- ITA
- MEX
- NLD
- RUS
- SWE
- USA
## Test
```sh
$ 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:
```javascript
const { RegionIdentifier } = requrie('regionIdentifier');
const identifier = new RegionIdentifier('');
```
#### Get region:
```javascript
//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);
});
```