Skip to content

Commit 62d2ec4

Browse files
Improve getMetadata prioritization (GH-27)
2 parents d175f23 + 8d2d832 commit 62d2ec4

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.3",
2+
"version": "0.1.4",
33
"name": "react-phone-hooks",
44
"description": "React hooks and utility functions for parsing and validating phone numbers.",
55
"keywords": [

src/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ const slots = new Set(".");
1010

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

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

0 commit comments

Comments
 (0)