From 80cd88e15d4393ad6c4863041147a14da1ff23a9 Mon Sep 17 00:00:00 2001 From: Artyom Vancyan Date: Sat, 20 Jul 2024 14:52:23 +0400 Subject: [PATCH 1/3] GH-41: Drop support for toll-free numbers --- scripts/prepare-metadata/__main__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/prepare-metadata/__main__.py b/scripts/prepare-metadata/__main__.py index dc8a823..05b9137 100644 --- a/scripts/prepare-metadata/__main__.py +++ b/scripts/prepare-metadata/__main__.py @@ -27,7 +27,7 @@ def update_mask(mask, length): while len(pn_mask.replace(" ", "")) > pn_mask_expected_length: pn_mask = pn_mask[:-1] mask = f"{cc_mask} {ac_mask} {pn_mask}" if ac_mask else f"{cc_mask} {pn_mask}" - return re.sub(r"\s(\.{1,2})$", r"\1", mask) + return re.sub(r"\s(\.)$", r"\1", mask) with open(patterns_path) as fp: @@ -36,9 +36,10 @@ def update_mask(mask, length): with open(countries_path) as fp: countries = json.load(fp) -for territory in territories: +for territory in filter(lambda t: t.get("id").isalpha(), territories): # Regenerate masks based on possible maximum lengths - possible_lengths = map(lambda e: territory.find(f"{e.tag}/possibleLengths"), territory.iter()) + possible_lengths = map(lambda e: territory.find(f"{e.tag}/possibleLengths") if e.tag != "tollFree" else None, + territory.iter()) possible_lengths = map(lambda e: e.get("national"), filter(lambda e: e is not None, possible_lengths)) possible_lengths = list(map(int, re.findall(r"\d+", ",".join(possible_lengths)))) min_length, max_length = min(possible_lengths), max(possible_lengths) From 485510155521f96d42431daa183b3f8299dc6822 Mon Sep 17 00:00:00 2001 From: Artyom Vancyan Date: Sat, 20 Jul 2024 14:53:07 +0400 Subject: [PATCH 2/3] GH-41: Update input masks --- src/metadata/countries.json | 104 +++++++++++++++++++++------------- src/metadata/validations.json | 62 ++++++++++---------- 2 files changed, 95 insertions(+), 71 deletions(-) diff --git a/src/metadata/countries.json b/src/metadata/countries.json index 8914ded..fd81a58 100644 --- a/src/metadata/countries.json +++ b/src/metadata/countries.json @@ -309,7 +309,7 @@ "bz", "Belize", "501", - "+501 (...) .... ...." + "+501 (...) ...." ], [ "bj", @@ -345,7 +345,7 @@ "bw", "Botswana", "267", - "+267 (..) ... ....." + "+267 (..) ... ..." ], [ "br", @@ -375,7 +375,7 @@ "bg", "Bulgaria", "359", - "+359 (...) ... ... ..." + "+359 (...) ... ..." ], [ "bf", @@ -807,7 +807,7 @@ "ec", "Ecuador", "593", - "+593 (..) ... ... ..." + "+593 (..) ... ...." ], [ "eg", @@ -837,7 +837,31 @@ "ee", "Estonia", "372", - "+372 (....) ... ..." + "+372 (...) ...." + ], + [ + "ee", + "Estonia", + "37287", + "+372 (87.) ...." + ], + [ + "ee", + "Estonia", + "3725", + "+372 (5...) ...." + ], + [ + "ee", + "Estonia", + "3728", + "+372 (8...) ...." + ], + [ + "ee", + "Estonia", + "37240", + "+372 (40..) ...." ], [ "et", @@ -861,7 +885,7 @@ "fj", "Fiji", "679", - "+679 (..) ... ... ..." + "+679 (..) ....." ], [ "fi", @@ -885,7 +909,7 @@ "pf", "French Polynesia", "689", - "+689 (..) ... ...." + "+689 (..) ... ..." ], [ "ga", @@ -927,7 +951,7 @@ "gr", "Greece", "30", - "+30 (...) ... ... ..." + "+30 (...) ... ...." ], [ "gl", @@ -1077,91 +1101,91 @@ "kz", "Kazakhstan", "7310", - "+7 (310) ... ... ....." + "+7 (310) ... ...." ], [ "kz", "Kazakhstan", "7311", - "+7 (311) ... ... ....." + "+7 (311) ... ...." ], [ "kz", "Kazakhstan", "7312", - "+7 (312) ... ... ....." + "+7 (312) ... ...." ], [ "kz", "Kazakhstan", "7313", - "+7 (313) ... ... ....." + "+7 (313) ... ...." ], [ "kz", "Kazakhstan", "7315", - "+7 (315) ... ... ....." + "+7 (315) ... ...." ], [ "kz", "Kazakhstan", "7318", - "+7 (318) ... ... ....." + "+7 (318) ... ...." ], [ "kz", "Kazakhstan", "7321", - "+7 (321) ... ... ....." + "+7 (321) ... ...." ], [ "kz", "Kazakhstan", "7324", - "+7 (324) ... ... ....." + "+7 (324) ... ...." ], [ "kz", "Kazakhstan", "7325", - "+7 (325) ... ... ....." + "+7 (325) ... ...." ], [ "kz", "Kazakhstan", "7326", - "+7 (326) ... ... ....." + "+7 (326) ... ...." ], [ "kz", "Kazakhstan", "7327", - "+7 (327) ... ... ....." + "+7 (327) ... ...." ], [ "kz", "Kazakhstan", "7336", - "+7 (336) ... ... ....." + "+7 (336) ... ...." ], [ "kz", "Kazakhstan", "77172", - "+7 (717) 2.. ... ....." + "+7 (717) 2.. ...." ], [ "kz", "Kazakhstan", "773622", - "+7 (736) 22. ... ....." + "+7 (736) 22. ...." ], [ "ke", "Kenya", "254", - "+254 (...) ... ...." + "+254 (...) ... ..." ], [ "ki", @@ -1185,7 +1209,7 @@ "kg", "Kyrgyzstan", "996", - "+996 (...) ... ...." + "+996 (...) ... ..." ], [ "la", @@ -1311,7 +1335,7 @@ "mu", "Mauritius", "230", - "+230 (...) ... ...." + "+230 (...) ....." ], [ "mx", @@ -1617,7 +1641,7 @@ "me", "Montenegro", "382", - "+382 (..) ... ...." + "+382 (..) ... ..." ], [ "ms", @@ -1659,7 +1683,7 @@ "np", "Nepal", "977", - "+977 (..) ... ... ..." + "+977 (..) ... ....." ], [ "nl", @@ -1731,7 +1755,7 @@ "om", "Oman", "968", - "+968 (..) ... ...." + "+968 (..) ... ..." ], [ "pk", @@ -1755,7 +1779,7 @@ "pa", "Panama", "507", - "+507 (...) ... ....." + "+507 (...) ....." ], [ "pg", @@ -1767,7 +1791,7 @@ "py", "Paraguay", "595", - "+595 (...) ... ....." + "+595 (...) ... ..." ], [ "pe", @@ -1779,13 +1803,13 @@ "ph", "Philippines", "63", - "+63 (...) ... ... ...." + "+63 (...) ... ...." ], [ "pl", "Poland", "48", - "+48 (...) ... ...." + "+48 (...) ... ..." ], [ "pt", @@ -1809,7 +1833,7 @@ "qa", "Qatar", "974", - "+974 (....) .... ..." + "+974 (....) ...." ], [ "ro", @@ -1821,7 +1845,7 @@ "ru", "Russia", "7", - "+7 (...) ... ... ....." + "+7 (...) ... ...." ], [ "rw", @@ -2037,7 +2061,7 @@ "th", "Thailand", "66", - "+66 (..) ... ... ....." + "+66 (..) ... ....." ], [ "tl", @@ -2079,7 +2103,7 @@ "tr", "Turkey", "90", - "+90 (...) ... ... ...." + "+90 (...) ... .. .." ], [ "tm", @@ -2121,13 +2145,13 @@ "ae", "United Arab Emirates", "971", - "+971 (.) ... ... ....." + "+971 (.) ... ....." ], [ "ae", "United Arab Emirates", "9715", - "+971 (..) ... ... ...." + "+971 (..) ... ...." ], [ "gb", @@ -3591,7 +3615,7 @@ "uy", "Uruguay", "598", - "+598 (.) ... ... ... ..." + "+598 (.) ... ...." ], [ "uz", @@ -3627,7 +3651,7 @@ "wf", "Wallis & Futuna", "681", - "+681 (..) ... ...." + "+681 (..) ...." ], [ "ye", diff --git a/src/metadata/validations.json b/src/metadata/validations.json index 5e2c528..364d14f 100644 --- a/src/metadata/validations.json +++ b/src/metadata/validations.json @@ -4,7 +4,7 @@ "^(?:1|6\\d)\\d{7}|[135-9]\\d{5}$" ], "ae": [ - "^\\d{5,12}$", + "^\\d{8,9}$", "^(?:[4-7]\\d|9[0-689])\\d{7}|800\\d{2,9}|[2-4679]\\d{7}$" ], "af": [ @@ -76,7 +76,7 @@ "^[025-7]\\d{7}$" ], "bg": [ - "^\\d{6,12}$", + "^\\d{6,9}$", "^00800\\d{7}|[2-7]\\d{6,7}|[89]\\d{6,8}|2\\d{5}$" ], "bh": [ @@ -120,7 +120,7 @@ "^[17]\\d{7}|[2-8]\\d{6}$" ], "bw": [ - "^\\d{7,10}$", + "^\\d{7,8}$", "^(?:0800|(?:[37]|800)\\d)\\d{6}|(?:[2-6]\\d|90)\\d{5}$" ], "by": [ @@ -128,7 +128,7 @@ "^(?:[12]\\d|33|44|902)\\d{7}|8(?:0[0-79]\\d{5,7}|[1-7]\\d{9})|8(?:1[0-489]|[5-79]\\d)\\d{7}|8[1-79]\\d{6,7}|8[0-79]\\d{5}|8\\d{5}$" ], "bz": [ - "^\\d{7,11}$", + "^\\d{7}$", "^(?:0800\\d|[2-8])\\d{6}$" ], "ca": [ @@ -164,7 +164,7 @@ "^12300\\d{6}|6\\d{9,10}|[2-9]\\d{8}$" ], "cm": [ - "^\\d{8,9}$", + "^\\d{9}$", "^[26]\\d{8}|88\\d{6,7}$" ], "cn": [ @@ -224,11 +224,11 @@ "^(?:[1-4]|[5-79]\\d|80)\\d{7}$" ], "ec": [ - "^\\d{8,11}$", + "^\\d{8,9}$", "^1\\d{9,10}|(?:[2-7]|9\\d)\\d{7}$" ], "ee": [ - "^\\d{7,10}$", + "^\\d{7,8}$", "^8\\d{9}|[4578]\\d{7}|(?:[3-8]\\d|90)\\d{5}$" ], "eg": [ @@ -252,7 +252,7 @@ "^[1-35689]\\d{4}|7\\d{10,11}|(?:[124-7]\\d|3[0-46-9])\\d{8}|[1-9]\\d{5,8}$" ], "fj": [ - "^\\d{7,11}$", + "^\\d{7}$", "^45\\d{5}|(?:0800\\d|[235-9])\\d{6}$" ], "fk": [ @@ -320,7 +320,7 @@ "^222\\d{6}|(?:3\\d|55|[89]0)\\d{7}$" ], "gr": [ - "^\\d{10,12}$", + "^\\d{10}$", "^5005000\\d{3}|8\\d{9,11}|(?:[269]\\d|70)\\d{8}$" ], "gt": [ @@ -368,7 +368,7 @@ "^(?:1\\d|[2569])\\d{6,8}|4\\d{6,9}|7\\d{8}|8\\d{8,9}$" ], "il": [ - "^\\d{7,12}$", + "^\\d{8,12}$", "^1\\d{6}(?:\\d{3,5})?|[57]\\d{8}|[1-489]\\d{7}$" ], "in": [ @@ -412,11 +412,11 @@ "^00[1-9]\\d{6,14}|[257-9]\\d{9}|(?:00|[1-9]\\d\\d)\\d{6}$" ], "ke": [ - "^\\d{7,10}$", + "^\\d{7,9}$", "^(?:[17]\\d\\d|900)\\d{6}|(?:2|80)0\\d{6,7}|[4-6]\\d{6,8}$" ], "kg": [ - "^\\d{9,10}$", + "^\\d{9}$", "^8\\d{9}|[235-9]\\d{8}$" ], "kh": [ @@ -444,7 +444,7 @@ "^00[1-9]\\d{8,11}|(?:[12]|5\\d{3})\\d{7}|[13-6]\\d{9}|(?:[1-6]\\d|80)\\d{7}|[3-6]\\d{4,5}|(?:00|7)0\\d{8}$" ], "kw": [ - "^\\d{7,8}$", + "^\\d{8}$", "^18\\d{5}|(?:[2569]\\d|41)\\d{6}$" ], "ky": [ @@ -452,7 +452,7 @@ "^(?:345|[58]\\d\\d|900)\\d{7}$" ], "kz": [ - "^\\d{10,14}$", + "^\\d{10}$", "^(?:33622|8\\d{8})\\d{5}|[78]\\d{9}$" ], "la": [ @@ -512,7 +512,7 @@ "^(?:[235-7]\\d|[89]0)\\d{6}$" ], "me": [ - "^\\d{8,9}$", + "^\\d{8}$", "^(?:20|[3-79]\\d)\\d{6}|80\\d{6,7}$" ], "mg": [ @@ -540,7 +540,7 @@ "^[12]\\d{7,9}|[5-9]\\d{7}$" ], "mo": [ - "^\\d{7,8}$", + "^\\d{8}$", "^0800\\d{3}|(?:28|[68]\\d)\\d{6}$" ], "mp": [ @@ -564,7 +564,7 @@ "^3550\\d{4}|(?:[2579]\\d\\d|800)\\d{5}$" ], "mu": [ - "^\\d{7,10}$", + "^\\d{7,8}$", "^(?:[57]|8\\d\\d)\\d{7}|[2-468]\\d{6}$" ], "mv": [ @@ -620,7 +620,7 @@ "^(?:0|[2-9]\\d{3})\\d{4}$" ], "np": [ - "^\\d{8,11}$", + "^\\d{8,10}$", "^(?:1\\d|9)\\d{9}|[1-9]\\d{7}$" ], "nr": [ @@ -636,11 +636,11 @@ "^[1289]\\d{9}|50\\d{5}(?:\\d{2,3})?|[27-9]\\d{7,8}|(?:[34]\\d|6[0-35-9])\\d{6}|8\\d{4,6}$" ], "om": [ - "^\\d{7,9}$", + "^\\d{8}$", "^(?:1505|[279]\\d{3}|500)\\d{4}|800\\d{5,6}$" ], "pa": [ - "^\\d{7,11}$", + "^\\d{7,8}$", "^(?:00800|8\\d{3})\\d{6}|[68]\\d{7}|[1-57-9]\\d{6}$" ], "pe": [ @@ -648,7 +648,7 @@ "^(?:[14-8]|9\\d)\\d{7}$" ], "pf": [ - "^\\d{6,9}$", + "^\\d{6,8}$", "^4\\d{5}(?:\\d{2})?|8\\d{7,8}$" ], "pg": [ @@ -656,7 +656,7 @@ "^(?:180|[78]\\d{3})\\d{4}|(?:[2-589]\\d|64)\\d{5}$" ], "ph": [ - "^\\d{6,13}$", + "^\\d{6,10}$", "^(?:[2-7]|9\\d)\\d{8}|2\\d{5}|(?:1800|8)\\d{7,9}$" ], "pk": [ @@ -664,7 +664,7 @@ "^122\\d{6}|[24-8]\\d{10,11}|9(?:[013-9]\\d{8,10}|2(?:[01]\\d\\d|2(?:[06-8]\\d|1[01]))\\d{7})|(?:[2-8]\\d{3}|92(?:[0-7]\\d|8[1-9]))\\d{6}|[24-9]\\d{8}|[89]\\d{7}$" ], "pl": [ - "^\\d{6,10}$", + "^\\d{6,9}$", "^(?:6|8\\d\\d)\\d{7}|[1-9]\\d{6}(?:\\d{2})?|[26]\\d{5}$" ], "pm": [ @@ -688,11 +688,11 @@ "^(?:[24-8]\\d\\d|345|900)\\d{4}$" ], "py": [ - "^\\d{6,11}$", + "^\\d{6,9}$", "^59\\d{4,6}|9\\d{5,10}|(?:[2-46-8]\\d|5[0-8])\\d{4,7}$" ], "qa": [ - "^\\d{7,11}$", + "^\\d{7,8}$", "^800\\d{4}|(?:2|800)\\d{6}|(?:0080|[3-7])\\d{7}$" ], "re": [ @@ -708,7 +708,7 @@ "^38[02-9]\\d{6,9}|6\\d{7,9}|90\\d{4,8}|38\\d{5,6}|(?:7\\d\\d|800)\\d{3,9}|(?:[12]\\d|3[0-79])\\d{5,10}$" ], "ru": [ - "^\\d{10,14}$", + "^\\d{10}$", "^8\\d{13}|[347-9]\\d{9}$" ], "rw": [ @@ -732,7 +732,7 @@ "^[19]\\d{8}$" ], "se": [ - "^\\d{6,12}$", + "^\\d{7,12}$", "^(?:[26]\\d\\d|9)\\d{9}|[1-9]\\d{8}|[1-689]\\d{7}|[1-4689]\\d{6}|2\\d{5}$" ], "sg": [ @@ -808,7 +808,7 @@ "^[279]\\d{7}$" ], "th": [ - "^\\d{8,13}$", + "^\\d{8,10}$", "^(?:001800|[2-57]|[689]\\d)\\d{7}|1\\d{7,9}$" ], "tj": [ @@ -836,7 +836,7 @@ "^(?:0800|(?:[5-8]\\d\\d|999)\\d)\\d{3}|[2-8]\\d{4}$" ], "tr": [ - "^\\d{7,13}$", + "^\\d{7,10}$", "^4\\d{6}|8\\d{11,12}|(?:[2-58]\\d\\d|900)\\d{7}$" ], "tt": [ @@ -868,7 +868,7 @@ "^[2-9]\\d{9}|3\\d{6}$" ], "uy": [ - "^\\d{6,13}$", + "^\\d{7,8}$", "^0004\\d{2,9}|[1249]\\d{7}|(?:[49]\\d|80)\\d{5}$" ], "uz": [ @@ -904,7 +904,7 @@ "^[57-9]\\d{6}|(?:[238]\\d|48)\\d{3}$" ], "wf": [ - "^\\d{6,9}$", + "^\\d{6}$", "^(?:40|72)\\d{4}|8\\d{5}(?:\\d{3})?$" ], "ws": [ From d6a05d11d8258aecb135a600c89a139b3ef2b8ed Mon Sep 17 00:00:00 2001 From: Artyom Vancyan Date: Sat, 20 Jul 2024 14:58:14 +0400 Subject: [PATCH 3/3] Upgrade the version to `0.1.8` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a6e039d..958540d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.1.7", + "version": "0.1.8", "name": "react-phone-hooks", "description": "React hooks and utility functions for parsing and validating phone numbers.", "keywords": [