Skip to content
Open
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Utility module that provides an easy way to identify the region of the country d
#### Predefined Regions
- AUS
- AUT
- BRA
- BEL
- CAN
- CHE
Expand All @@ -23,12 +24,18 @@ Utility module that provides an easy way to identify the region of the country d
- IRL
- ITA
- JPN
- KOR
- LTU
- LUX
- MEX
- NLD
- PRT
- RUS
- ROU
- SVK
- SRB
- SWE
- TUR
- USA

## Test
Expand Down
4 changes: 4 additions & 0 deletions country/BRA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 8
}
4 changes: 4 additions & 0 deletions country/KOR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 5
}
4 changes: 4 additions & 0 deletions country/LTU.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 5
}
4 changes: 4 additions & 0 deletions country/LUX.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/PRT.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/SVK.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 5
}
4 changes: 4 additions & 0 deletions country/TUR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zipCodeFormat": "numeric",
"zipCodeLength": 5
}
35 changes: 35 additions & 0 deletions lib/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { GoogleMapsAPIError } = require('./errors');
const availableCountries = new Set([
'AUS',
'AUT',
'BRA',
'BEL',
'CAN',
'CHE',
Expand All @@ -20,12 +21,18 @@ const availableCountries = new Set([
'IRL',
'ITA',
'JPN',
'KOR',
'LTU',
'LUX',
'MEX',
'NLD',
'PRT',
'RUS',
'ROU',
'SVK',
'SRB',
'SWE',
'TUR',
'USA',
]);

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

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

case 'HUN': {
return zip.replaceAll(/\D/g, '').slice(0, 4);
}
Expand All @@ -106,6 +117,18 @@ function validateZipCode(country, zip) {
return zip.replaceAll(/\D/g, '').slice(0, 7);
}

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

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

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

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

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

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

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

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

default: {
return zip;
}
Expand Down
29 changes: 29 additions & 0 deletions regionNames/BRA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"BR-AC": "Acre",
"BR-AL": "Alagoas",
"BR-AM": "Amazonas",
"BR-AP": "Amapá",
"BR-BA": "Bahia",
"BR-CE": "Ceará",
"BR-DF": "Distrito Federal",
"BR-ES": "Espírito Santo",
"BR-GO": "Goiás",
"BR-MA": "Maranhão",
"BR-MG": "Minas Gerais",
"BR-MS": "Mato Grosso do Sul",
"BR-MT": "Mato Grosso",
"BR-PA": "Pará",
"BR-PB": "Paraíba",
"BR-PE": "Pernambuco",
"BR-PI": "Piauí",
"BR-PR": "Paraná",
"BR-RJ": "Rio de Janeiro",
"BR-RN": "Rio Grande do Norte",
"BR-RO": "Rondônia",
"BR-RR": "Roraima",
"BR-RS": "Rio Grande do Sul",
"BR-SC": "Santa Catarina",
"BR-SE": "Sergipe",
"BR-SP": "São Paulo",
"BR-TO": "Tocantins"
}
19 changes: 19 additions & 0 deletions regionNames/KOR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"KR-11": "Seoul-teukbyeolsi",
"KR-26": "Busan-gwangyeoksi",
"KR-27": "Daegu-gwangyeoksi",
"KR-28": "Incheon-gwangyeoksi",
"KR-29": "Gwangju-gwangyeoksi",
"KR-30": "Daejeon-gwangyeoksi",
"KR-31": "Ulsan-gwangyeoksi",
"KR-41": "Gyeonggi-do",
"KR-42": "Gangwon-teukbyeoljachido",
"KR-43": "Chungcheongbuk-do",
"KR-44": "Chungcheongnam-do",
"KR-45": "Jeollabuk-do",
"KR-46": "Jeollanam-do",
"KR-47": "Gyeongsangbuk-do",
"KR-48": "Gyeongsangnam-do",
"KR-49": "Jeju-teukbyeoljachido",
"KR-50": "Sejong"
}
12 changes: 12 additions & 0 deletions regionNames/LTU.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"LT-03": "Alytus",
"LT-16": "Kaunas",
"LT-21": "Klaipėda",
"LT-25": "Marijampolė",
"LT-33": "Panevėžys",
"LT-44": "Šiauliai",
"LT-50": "Tauragė",
"LT-51": "Telšiai",
"LT-54": "Utena",
"LT-58": "Vilnius"
}
14 changes: 14 additions & 0 deletions regionNames/LUX.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"LU-CA": "Capellen",
"LU-CL": "Clervaux",
"LU-DI": "Diekirch",
"LU-EC": "Echternach",
"LU-ES": "Esch-sur-Alzette",
"LU-GR": "Grevenmacher",
"LU-LU": "Luxembourg",
"LU-ME": "Mersch",
"LU-RD": "Redange",
"LU-RM": "Remich",
"LU-VD": "Vianden",
"LU-WI": "Wiltz"
}
22 changes: 22 additions & 0 deletions regionNames/PRT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"PT-01": "Aveiro",
"PT-02": "Beja",
"PT-03": "Braga",
"PT-04": "Bragança",
"PT-05": "Castelo Branco",
"PT-06": "Coimbra",
"PT-07": "Évora",
"PT-08": "Faro",
"PT-09": "Guarda",
"PT-10": "Leiria",
"PT-11": "Lisboa",
"PT-12": "Portalegre",
"PT-13": "Porto",
"PT-14": "Santarém",
"PT-15": "Setúbal",
"PT-16": "Viana do Castelo",
"PT-17": "Vila Real",
"PT-18": "Viseu",
"PT-20": "Região Autónoma dos Açores",
"PT-30": "Região Autónoma da Madeira"
}
10 changes: 10 additions & 0 deletions regionNames/SVK.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"SK-BC": "Banskobystrický kraj",
"SK-BL": "Bratislavský kraj",
"SK-KI": "Košický kraj",
"SK-NI": "Nitriansky kraj",
"SK-PV": "Prešovský kraj",
"SK-TA": "Trnavský kraj",
"SK-TC": "Trenčiansky kraj",
"SK-ZI": "Žilinský kraj"
}
83 changes: 83 additions & 0 deletions regionNames/TUR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"TR-01": "Adana",
"TR-02": "Adıyaman",
"TR-03": "Afyonkarahisar",
"TR-04": "Ağrı",
"TR-05": "Amasya",
"TR-06": "Ankara",
"TR-07": "Antalya",
"TR-08": "Artvin",
"TR-09": "Aydın",
"TR-10": "Balıkesir",
"TR-11": "Bilecik",
"TR-12": "Bingöl",
"TR-13": "Bitlis",
"TR-14": "Bolu",
"TR-15": "Burdur",
"TR-16": "Bursa",
"TR-17": "Çanakkale",
"TR-18": "Çankırı",
"TR-19": "Çorum",
"TR-20": "Denizli",
"TR-21": "Diyarbakır",
"TR-22": "Edirne",
"TR-23": "Elazığ",
"TR-24": "Erzincan",
"TR-25": "Erzurum",
"TR-26": "Eskişehir",
"TR-27": "Gaziantep",
"TR-28": "Giresun",
"TR-29": "Gümüşhane",
"TR-30": "Hakkâri",
"TR-31": "Hatay",
"TR-32": "Isparta",
"TR-33": "Mersin",
"TR-34": "İstanbul",
"TR-35": "İzmir",
"TR-36": "Kars",
"TR-37": "Kastamonu",
"TR-38": "Kayseri",
"TR-39": "Kırklareli",
"TR-40": "Kırşehir",
"TR-41": "Kocaeli",
"TR-42": "Konya",
"TR-43": "Kütahya",
"TR-44": "Malatya",
"TR-45": "Manisa",
"TR-46": "Kahramanmaraş",
"TR-47": "Mardin",
"TR-48": "Muğla",
"TR-49": "Muş",
"TR-50": "Nevşehir",
"TR-51": "Niğde",
"TR-52": "Ordu",
"TR-53": "Rize",
"TR-54": "Sakarya",
"TR-55": "Samsun",
"TR-56": "Siirt",
"TR-57": "Sinop",
"TR-58": "Sivas",
"TR-59": "Tekirdağ",
"TR-60": "Tokat",
"TR-61": "Trabzon",
"TR-62": "Tunceli",
"TR-63": "Şanlıurfa",
"TR-64": "Uşak",
"TR-65": "Van",
"TR-66": "Yozgat",
"TR-67": "Zonguldak",
"TR-68": "Aksaray",
"TR-69": "Bayburt",
"TR-70": "Karaman",
"TR-71": "Kırıkkale",
"TR-72": "Batman",
"TR-73": "Şırnak",
"TR-74": "Bartın",
"TR-75": "Ardahan",
"TR-76": "Iğdır",
"TR-77": "Yalova",
"TR-78": "Karabük",
"TR-79": "Kilis",
"TR-80": "Osmaniye",
"TR-81": "Düzce"
}
Loading