Skip to content

Commit

Permalink
Fix: country names with accents should not be pushed to end of list
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed Jul 26, 2024
1 parent 3f599fe commit 9439a1b
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 103 deletions.
15 changes: 5 additions & 10 deletions build/js/intlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1568,12 +1568,13 @@ var factoryOutput = (() => {
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -1588,13 +1589,7 @@ var factoryOutput = (() => {
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInput.min.js

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions build/js/intlTelInputWithUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,12 +1567,13 @@ var factoryOutput = (() => {
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -1587,13 +1588,7 @@ var factoryOutput = (() => {
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
2 changes: 1 addition & 1 deletion build/js/intlTelInputWithUtils.min.js

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions react/build/IntlTelInput.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,12 +1563,13 @@ var Iti = class {
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -1583,13 +1584,7 @@ var Iti = class {
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
15 changes: 5 additions & 10 deletions react/build/IntlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1527,12 +1527,13 @@ var Iti = class {
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -1547,13 +1548,7 @@ var Iti = class {
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
15 changes: 5 additions & 10 deletions react/build/IntlTelInputWithUtils.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,12 +1563,13 @@ var Iti = class {
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -1583,13 +1584,7 @@ var Iti = class {
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
15 changes: 5 additions & 10 deletions react/build/IntlTelInputWithUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1527,12 +1527,13 @@ var Iti = class {
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -1547,13 +1548,7 @@ var Iti = class {
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
15 changes: 5 additions & 10 deletions react/demo/set-number-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25056,12 +25056,13 @@
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -25076,13 +25077,7 @@
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
15 changes: 5 additions & 10 deletions react/demo/simple-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25056,12 +25056,13 @@
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -25076,13 +25077,7 @@
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
15 changes: 5 additions & 10 deletions react/demo/validation-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25056,12 +25056,13 @@
this._processAllCountries();
this._processDialCodes();
this._translateCountryNames();
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a, b) => {
const { countryOrder } = this.options;
if (countryOrder) {
Expand All @@ -25076,13 +25077,7 @@
return aIndexExists ? -1 : 1;
}
}
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
Expand Down
17 changes: 6 additions & 11 deletions src/js/intl-tel-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,14 @@ export class Iti {
this._translateCountryNames();

//* Sort countries by countryOrder option (if present), then name.
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this._sortCountries();
}


//* Sort countries by countryOrder option (if present), then name.
private _sortCountries() {
if (this.options.countryOrder) {
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
}
this.countries.sort((a: Country, b: Country): number => {
//* Primary sort: countryOrder option.
const { countryOrder } = this.options;
Expand All @@ -655,13 +656,7 @@ export class Iti {
}

//* Secondary sort: country name.
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
return a.name.localeCompare(b.name);
});
}

Expand Down

0 comments on commit 9439a1b

Please sign in to comment.