Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Utility module that provides an easy way to identify the region of the country d
* https://download.geonames.org/export/zip/ - all the Geoname files for download (see below)

#### Predefined Regions
- AUS
- AUT
- BEL
- CAN
Expand All @@ -17,10 +18,15 @@ Utility module that provides an easy way to identify the region of the country d
- FIN
- FRA
- GBR
- HUN
- IND
- IRL
- ITA
- JPN
- MEX
- NLD
- RUS
- ROU
- SRB
- SWE
- USA
Expand Down
4 changes: 4 additions & 0 deletions country/HUN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 4
}
4 changes: 4 additions & 0 deletions country/IND.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 6
}
3 changes: 3 additions & 0 deletions country/IRL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zipCodeFormat": "alpha"
}
4 changes: 4 additions & 0 deletions country/JPN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 7
}
4 changes: 4 additions & 0 deletions country/ROU.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 6
}
27 changes: 26 additions & 1 deletion lib/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { GoogleMapsAPIError } = require('./errors');

// supported countries
const availableCountries = new Set([
'AUS',
'AUT',
'BEL',
'CAN',
Expand All @@ -14,14 +15,18 @@ const availableCountries = new Set([
'FIN',
'FRA',
'GBR',
'HUN',
'IND',
'IRL',
'ITA',
'JPN',
'MEX',
'NLD',
'RUS',
'ROU',
'SRB',
'SWE',
'USA',
'AUS',
]);

//////////////////////
Expand Down Expand Up @@ -85,6 +90,22 @@ function validateZipCode(country, zip) {
return zip.startsWith('X') ? zip.slice(0, 3) : zip.slice(0, 1);
}

case 'HUN': {
return zip.replaceAll(/\D/g, '').slice(0, 4);
}

case 'IND': {
return zip.replaceAll(/\D/g, '').slice(0, 6);
}

case 'IRL': {
return zip.replaceAll(/\s/g, '').toUpperCase().slice(0, 3);
}

case 'JPN': {
return zip.replaceAll(/\D/g, '').slice(0, 7);
}

case 'NLD': {
return zip.split(' ')[0];
}
Expand All @@ -93,6 +114,10 @@ function validateZipCode(country, zip) {
return zip.slice(0, 2);
}

case 'ROU': {
return zip.replaceAll(/\D/g, '').slice(0, 6);
}

default: {
return zip;
}
Expand Down
22 changes: 22 additions & 0 deletions regionNames/HUN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"HU-BA": "Baranya",
"HU-BE": "Békés",
"HU-BK": "Bács-Kiskun",
"HU-BU": "Budapest",
"HU-BZ": "Borsod-Abaúj-Zemplén",
"HU-CS": "Csongrád-Csanád",
"HU-FE": "Fejér",
"HU-GS": "Győr-Moson-Sopron",
"HU-HB": "Hajdú-Bihar",
"HU-HE": "Heves",
"HU-JN": "Jász-Nagykun-Szolnok",
"HU-KE": "Komárom-Esztergom",
"HU-NO": "Nógrád",
"HU-PE": "Pest",
"HU-SO": "Somogy",
"HU-SZ": "Szabolcs-Szatmár-Bereg",
"HU-TO": "Tolna",
"HU-VA": "Vas",
"HU-VE": "Veszprém",
"HU-ZA": "Zala"
}
37 changes: 37 additions & 0 deletions regionNames/IND.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"IN-AN": "Andaman and Nicobar Islands",
"IN-AP": "Andhra Pradesh",
"IN-AR": "Arunāchal Pradesh",
"IN-AS": "Assam",
"IN-BR": "Bihār",
"IN-CG": "Chhattīsgarh",
"IN-CH": "Chandīgarh",
"IN-DH": "Dādra and Nagar Haveli and Damān and Diu",
"IN-DL": "Delhi",
"IN-GA": "Goa",
"IN-GJ": "Gujarāt",
"IN-HP": "Himāchal Pradesh",
"IN-HR": "Haryāna",
"IN-JH": "Jhārkhand",
"IN-JK": "Jammu and Kashmīr",
"IN-KA": "Karnātaka",
"IN-KL": "Kerala",
"IN-LD": "Lakshadweep",
"IN-MH": "Mahārāshtra",
"IN-ML": "Meghālaya",
"IN-MN": "Manipur",
"IN-MP": "Madhya Pradesh",
"IN-MZ": "Mizoram",
"IN-NL": "Nāgāland",
"IN-OD": "Odisha",
"IN-PB": "Punjab",
"IN-PY": "Puducherry",
"IN-RJ": "Rājasthān",
"IN-SK": "Sikkim",
"IN-TN": "Tamil Nādu",
"IN-TR": "Tripura",
"IN-TS": "Telangāna",
"IN-UK": "Uttarākhand",
"IN-UP": "Uttar Pradesh",
"IN-WB": "West Bengal"
}
6 changes: 6 additions & 0 deletions regionNames/IRL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"IE-C": "Connaught",
"IE-L": "Leinster",
"IE-M": "Munster",
"IE-U": "Ulster"
}
49 changes: 49 additions & 0 deletions regionNames/JPN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"JP-01": "Hokkaido",
"JP-02": "Aomori",
"JP-03": "Iwate",
"JP-04": "Miyagi",
"JP-05": "Akita",
"JP-06": "Yamagata",
"JP-07": "Fukushima",
"JP-08": "Ibaraki",
"JP-09": "Tochigi",
"JP-10": "Gunma",
"JP-11": "Saitama",
"JP-12": "Chiba",
"JP-13": "Tokyo",
"JP-14": "Kanagawa",
"JP-15": "Niigata",
"JP-16": "Toyama",
"JP-17": "Ishikawa",
"JP-18": "Fukui",
"JP-19": "Yamanashi",
"JP-20": "Nagano",
"JP-21": "Gifu",
"JP-22": "Shizuoka",
"JP-23": "Aichi",
"JP-24": "Mie",
"JP-25": "Shiga",
"JP-26": "Kyoto",
"JP-27": "Osaka",
"JP-28": "Hyogo",
"JP-29": "Nara",
"JP-30": "Wakayama",
"JP-31": "Tottori",
"JP-32": "Shimane",
"JP-33": "Okayama",
"JP-34": "Hiroshima",
"JP-35": "Yamaguchi",
"JP-36": "Tokushima",
"JP-37": "Kagawa",
"JP-38": "Ehime",
"JP-39": "Kochi",
"JP-40": "Fukuoka",
"JP-41": "Saga",
"JP-42": "Nagasaki",
"JP-43": "Kumamoto",
"JP-44": "Oita",
"JP-45": "Miyazaki",
"JP-46": "Kagoshima",
"JP-47": "Okinawa"
}
44 changes: 44 additions & 0 deletions regionNames/ROU.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"RO-AB": "Alba",
"RO-AG": "Argeș",
"RO-AR": "Arad",
"RO-B": "București",
"RO-BC": "Bacău",
"RO-BH": "Bihor",
"RO-BN": "Bistrița-Năsăud",
"RO-BR": "Brăila",
"RO-BT": "Botoșani",
"RO-BV": "Brașov",
"RO-BZ": "Buzău",
"RO-CJ": "Cluj",
"RO-CL": "Călărași",
"RO-CS": "Caraș-Severin",
"RO-CT": "Constanța",
"RO-CV": "Covasna",
"RO-DB": "Dâmbovița",
"RO-DJ": "Dolj",
"RO-GJ": "Gorj",
"RO-GL": "Galați",
"RO-GR": "Giurgiu",
"RO-HD": "Hunedoara",
"RO-HR": "Harghita",
"RO-IF": "Ilfov",
"RO-IL": "Ialomița",
"RO-IS": "Iași",
"RO-MH": "Mehedinți",
"RO-MM": "Maramureș",
"RO-MS": "Mureș",
"RO-NT": "Neamț",
"RO-OT": "Olt",
"RO-PH": "Prahova",
"RO-SB": "Sibiu",
"RO-SJ": "Sălaj",
"RO-SM": "Satu Mare",
"RO-SV": "Suceava",
"RO-TL": "Tulcea",
"RO-TM": "Timiș",
"RO-TR": "Teleorman",
"RO-VL": "Vâlcea",
"RO-VN": "Vrancea",
"RO-VS": "Vaslui"
}
Loading