Skip to content

Commit

Permalink
Improve getMetadata prioritization (GH-27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyomVancyan authored May 4, 2024
2 parents d175f23 + 8d2d832 commit 62d2ec4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 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.3",
"version": "0.1.4",
"name": "react-phone-hooks",
"description": "React hooks and utility functions for parsing and validating phone numbers.",
"keywords": [
Expand Down
7 changes: 2 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ const slots = new Set(".");

export const getMetadata = (rawValue: string, countriesList: typeof countries = countries, country: any = null) => {
country = country == null && rawValue.startsWith("44") ? "gb" : country;
if (country != null) {
countriesList = countriesList.filter((c) => c[0] === country);
countriesList = countriesList.sort((a, b) => b[2].length - a[2].length);
}
return countriesList.find((c) => rawValue.startsWith(c[2]));
if (country != null) countriesList = countriesList.filter((c) => c[0] === country);
return [...countriesList].sort((a, b) => b[2].length - a[2].length).find((c) => rawValue.startsWith(c[2]));
}

export const getCountry = (countryCode: keyof typeof countries) => {
Expand Down

0 comments on commit 62d2ec4

Please sign in to comment.