Skip to content

Commit

Permalink
Drop support of the toll free numbers (GH-42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyomVancyan authored Jul 20, 2024
2 parents 2f312b7 + d6a05d1 commit dfa9e86
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 75 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
7 changes: 4 additions & 3 deletions scripts/prepare-metadata/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
104 changes: 64 additions & 40 deletions src/metadata/countries.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
"bz",
"Belize",
"501",
"+501 (...) .... ...."
"+501 (...) ...."
],
[
"bj",
Expand Down Expand Up @@ -345,7 +345,7 @@
"bw",
"Botswana",
"267",
"+267 (..) ... ....."
"+267 (..) ... ..."
],
[
"br",
Expand Down Expand Up @@ -375,7 +375,7 @@
"bg",
"Bulgaria",
"359",
"+359 (...) ... ... ..."
"+359 (...) ... ..."
],
[
"bf",
Expand Down Expand Up @@ -807,7 +807,7 @@
"ec",
"Ecuador",
"593",
"+593 (..) ... ... ..."
"+593 (..) ... ...."
],
[
"eg",
Expand Down Expand Up @@ -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",
Expand All @@ -861,7 +885,7 @@
"fj",
"Fiji",
"679",
"+679 (..) ... ... ..."
"+679 (..) ....."
],
[
"fi",
Expand All @@ -885,7 +909,7 @@
"pf",
"French Polynesia",
"689",
"+689 (..) ... ...."
"+689 (..) ... ..."
],
[
"ga",
Expand Down Expand Up @@ -927,7 +951,7 @@
"gr",
"Greece",
"30",
"+30 (...) ... ... ..."
"+30 (...) ... ...."
],
[
"gl",
Expand Down Expand Up @@ -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",
Expand All @@ -1185,7 +1209,7 @@
"kg",
"Kyrgyzstan",
"996",
"+996 (...) ... ...."
"+996 (...) ... ..."
],
[
"la",
Expand Down Expand Up @@ -1311,7 +1335,7 @@
"mu",
"Mauritius",
"230",
"+230 (...) ... ...."
"+230 (...) ....."
],
[
"mx",
Expand Down Expand Up @@ -1617,7 +1641,7 @@
"me",
"Montenegro",
"382",
"+382 (..) ... ...."
"+382 (..) ... ..."
],
[
"ms",
Expand Down Expand Up @@ -1659,7 +1683,7 @@
"np",
"Nepal",
"977",
"+977 (..) ... ... ..."
"+977 (..) ... ....."
],
[
"nl",
Expand Down Expand Up @@ -1731,7 +1755,7 @@
"om",
"Oman",
"968",
"+968 (..) ... ...."
"+968 (..) ... ..."
],
[
"pk",
Expand All @@ -1755,7 +1779,7 @@
"pa",
"Panama",
"507",
"+507 (...) ... ....."
"+507 (...) ....."
],
[
"pg",
Expand All @@ -1767,7 +1791,7 @@
"py",
"Paraguay",
"595",
"+595 (...) ... ....."
"+595 (...) ... ..."
],
[
"pe",
Expand All @@ -1779,13 +1803,13 @@
"ph",
"Philippines",
"63",
"+63 (...) ... ... ...."
"+63 (...) ... ...."
],
[
"pl",
"Poland",
"48",
"+48 (...) ... ...."
"+48 (...) ... ..."
],
[
"pt",
Expand All @@ -1809,7 +1833,7 @@
"qa",
"Qatar",
"974",
"+974 (....) .... ..."
"+974 (....) ...."
],
[
"ro",
Expand All @@ -1821,7 +1845,7 @@
"ru",
"Russia",
"7",
"+7 (...) ... ... ....."
"+7 (...) ... ...."
],
[
"rw",
Expand Down Expand Up @@ -2037,7 +2061,7 @@
"th",
"Thailand",
"66",
"+66 (..) ... ... ....."
"+66 (..) ... ....."
],
[
"tl",
Expand Down Expand Up @@ -2079,7 +2103,7 @@
"tr",
"Turkey",
"90",
"+90 (...) ... ... ...."
"+90 (...) ... .. .."
],
[
"tm",
Expand Down Expand Up @@ -2121,13 +2145,13 @@
"ae",
"United Arab Emirates",
"971",
"+971 (.) ... ... ....."
"+971 (.) ... ....."
],
[
"ae",
"United Arab Emirates",
"9715",
"+971 (..) ... ... ...."
"+971 (..) ... ...."
],
[
"gb",
Expand Down Expand Up @@ -3591,7 +3615,7 @@
"uy",
"Uruguay",
"598",
"+598 (.) ... ... ... ..."
"+598 (.) ... ...."
],
[
"uz",
Expand Down Expand Up @@ -3627,7 +3651,7 @@
"wf",
"Wallis & Futuna",
"681",
"+681 (..) ... ...."
"+681 (..) ...."
],
[
"ye",
Expand Down
Loading

0 comments on commit dfa9e86

Please sign in to comment.