From bd1757cf22f94f1c3cd64dc9c5099608510a8fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Maria=20Pay=C3=A1=20Castillo?= <30294138+jpaya17@users.noreply.github.com> Date: Wed, 15 Sep 2021 12:02:41 +0000 Subject: [PATCH] perf(isISO31661Alpha2): use a Set along with .has instead of includes fix(isBIC): refactor use of CountryCodes using Set's methods --- src/lib/isBIC.js | 2 +- src/lib/isISO31661Alpha2.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/isBIC.js b/src/lib/isBIC.js index 240bfe18b..b5576b24e 100644 --- a/src/lib/isBIC.js +++ b/src/lib/isBIC.js @@ -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; } diff --git a/src/lib/isISO31661Alpha2.js b/src/lib/isISO31661Alpha2.js index e91ae8717..e67bb1e15 100644 --- a/src/lib/isISO31661Alpha2.js +++ b/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', @@ -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;