Skip to content

Commit 675a592

Browse files
committed
Improve getMetadata prioritization
1 parent d175f23 commit 675a592

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/index.ts

Lines changed: 2 additions & 5 deletions
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)