Skip to content

Commit 5b04cc5

Browse files
authored
perf(isISO31661Alpha2): use a Set along with .has instead of includes (#1724)
fix(isBIC): refactor use of CountryCodes using Set's methods
1 parent 8c4b3b3 commit 5b04cc5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/lib/isBIC.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function isBIC(str) {
99

1010
// toUpperCase() should be removed when a new major version goes out that changes
1111
// the regex to [A-Z] (per the spec).
12-
if (CountryCodes.indexOf(str.slice(4, 6).toUpperCase()) < 0) {
12+
if (!CountryCodes.has(str.slice(4, 6).toUpperCase())) {
1313
return false;
1414
}
1515

src/lib/isISO31661Alpha2.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assertString from './util/assertString';
22

33
// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
4-
const validISO31661Alpha2CountriesCodes = [
4+
const validISO31661Alpha2CountriesCodes = new Set([
55
'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ',
66
'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ',
77
'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ',
@@ -27,11 +27,11 @@ const validISO31661Alpha2CountriesCodes = [
2727
'WF', 'WS',
2828
'YE', 'YT',
2929
'ZA', 'ZM', 'ZW',
30-
];
30+
]);
3131

3232
export default function isISO31661Alpha2(str) {
3333
assertString(str);
34-
return validISO31661Alpha2CountriesCodes.indexOf(str.toUpperCase()) >= 0;
34+
return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
3535
}
3636

3737
export const CountryCodes = validISO31661Alpha2CountriesCodes;

0 commit comments

Comments
 (0)