Skip to content

Commit

Permalink
perf(isISO31661Alpha2): use a Set along with .has instead of includes (
Browse files Browse the repository at this point in the history
…#1724)

fix(isBIC): refactor use of CountryCodes using Set's methods
  • Loading branch information
jmpaya committed Sep 20, 2021
1 parent 8c4b3b3 commit 5b04cc5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/isBIC.js
Expand Up @@ -9,7 +9,7 @@ export default function isBIC(str) {

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

Expand Down
6 changes: 3 additions & 3 deletions src/lib/isISO31661Alpha2.js
@@ -1,7 +1,7 @@
import assertString from './util/assertString';

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

export default function isISO31661Alpha2(str) {
assertString(str);
return validISO31661Alpha2CountriesCodes.indexOf(str.toUpperCase()) >= 0;
return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
}

export const CountryCodes = validISO31661Alpha2CountriesCodes;

0 comments on commit 5b04cc5

Please sign in to comment.