Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release staging: November 2021 release (13.7.0) #1853

Closed
wants to merge 69 commits into from
Closed
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
d1a9b6d
fix(isISO8601): disallow prepended and appended strings to RFC 3339 d…
Apr 21, 2021
907bb07
feat: added support for indonesian passport number (#1656)
rubiin May 24, 2021
2595554
feat: Export list of country codes that implement IBAN (#1669)
drorheller Jul 16, 2021
b82d4e1
feat:(isMobilePhone): add mobile number prefix 162 and 165 to zh-CN l…
laulujan Jul 16, 2021
c87956a
feat(isLicensePlate): Add Czech license plates (#1565)
filiptronicek Jul 16, 2021
044159d
feat(isBoolean) Add loose option to isBoolean validator (#1676)
Jul 16, 2021
01eeaef
feat(isMobilePhone): change the german prefix from '+490' to '+49' or…
AnnaMariaJansen Jul 16, 2021
cff8a2e
fix: npm installation error (#1697)
rubiin Jul 16, 2021
e08e79a
fix(sMobilePhone): regexp for Vietnamese phone number (#1689)
luisrivas Jul 16, 2021
d36f79c
chore: Increase coverage and make codecov more precise (#1658)
tux-tn Jul 16, 2021
f5f4fcd
feat(isIdentityCard): add TH (Thai) (#1657)
tithanayut Jul 16, 2021
8c4b3b3
chore: update pull_request_template.md (#1699)
fedeci Jul 19, 2021
5b04cc5
perf(isISO31661Alpha2): use a Set along with .has instead of includes…
jmpaya Sep 20, 2021
7376945
fix(isMagnetURI): update validation regex (#1730)
tux-tn Sep 21, 2021
f34112d
feat(isISO4217): add currency code validator (#1706)
jmpaya Sep 26, 2021
5b649c6
perf(isISO31661Alpha3): use a Set along with .has instead of includes…
jmpaya Sep 26, 2021
b0d49bd
fix(isDate): fix isdate format validation (#1711)
flymans Sep 26, 2021
69881b6
feat(isPassportNumber): fix regex for CN (#1714)
anirudhgiri Sep 26, 2021
e84623b
feat(isCreditCard): Fixed regex for Union Pay Credit cards with 81 ra…
shreyassai123 Sep 26, 2021
b069167
feat(isAlpha, isAlphanumeric): Adds Hindi (hi-IN) language support ad…
mikr13 Sep 26, 2021
a3497bd
fix(isEmail): replace all dots in gmail length validation (#1718)
DasDingGehtNicht Sep 26, 2021
326cfb9
feat(isURL): add `allow_fragments` and `allow_query_components` (#1721)
cowboy-bebug Sep 26, 2021
c899b31
feat(isMobilePhone): add validation for Venezuela phone numbers (#172…
islasjuanp Sep 26, 2021
05e382b
refactor: run scripts in parallel for build and clean (#1747)
sachinraja Oct 2, 2021
04b73ad
feat(isEmail): add `host_blacklist` option (#1641)
fedeci Oct 2, 2021
f2a1587
feat(isIdentityCard): Add PL locale (#1745)
wiktorwojcik112 Oct 2, 2021
4ec30b7
fix(isMobilePhone.js): regex for Belgium locale (#1746)
divikshrivastava Oct 2, 2021
13651ea
feat(isUrl): higher priority to whitelist (#1748)
deepanshu2506 Oct 5, 2021
622184e
feat(isFQDN): add `allow_wildcard` option (#1647)
fasenderos Oct 30, 2021
6b213cf
fix(isMobilePhone): use a loose and future-oriented way to verify Chi…
yisibl Oct 30, 2021
60dffb9
fix(isUrl): allow url with column and no port (#1751)
MatteoPierro Oct 30, 2021
29ed3a0
feat(isMobilePhone): add Cuba validation (#1765)
pasagedev Oct 30, 2021
9347d6d
fix(isUUID): fix for null version argument supply (#1777)
theteladras Oct 30, 2021
050a424
fix(isMobilePhone): regex for Pakistan(PK) (#1778)
hammad20120 Oct 30, 2021
5ed7db1
fix(isMobilePhone): update Sri Lanka locale (#1785)
Madhavi96 Oct 30, 2021
dc9f843
feat(isIdentityCard): add 'LK' (Sri Lanka) locale (#1786)
nimanthadilz Oct 30, 2021
8451206
feat(isPostalCode): add `LK` (Sri Lanka) locale (#1788)
nimanthadilz Oct 30, 2021
526417a
feat(isLicensePlate): add finnish locale (#1790)
Marcholio Oct 30, 2021
6eed6a4
fix(isFQDN): check more special chars (#1799)
MatteoPierro Oct 30, 2021
a837e6f
fix(isPassportNumber): update Poland country code (#1809)
Ronqn Oct 30, 2021
ba4106f
fix(isMobilePhone): update Hungarian locale (#1826)
danielTiringer Oct 30, 2021
c42b2d9
feat(isMobilePhone): add Bermuda en-BM locale (#1769)
HackProAIT Oct 30, 2021
7835db1
fix(docs): add missing locale (#1845)
profnandaa Oct 30, 2021
28f899d
feat(isUrl): urls with empty user (#1833)
MiguelSavignano Oct 30, 2021
3fcf768
fix(unescape): fixed bug where intermediate string contains escaped c…
Marcholio Oct 30, 2021
2201869
feat: added finnish locale to isAlpha and isAlphanumeric (#1837)
Marcholio Oct 30, 2021
57cc14e
feat(isIdentityCard): add finnish locale (#1838)
Marcholio Oct 30, 2021
7bee611
add CDN use option with unpkg (#1844)
Oct 30, 2021
de1cb29
fix: Russian passport number regex (#1810)
Theta-Dev Oct 30, 2021
5773869
feat(isVAT): add dutch NL locale (#1825)
zeno4ever Oct 30, 2021
f2381e0
feat: (isMobilePhone): add Cameroon fr-CM locale (#1772)
tarob0ba Oct 31, 2021
769f6d5
feat(contains): add possibility to check that string contains seed mu…
Marcholio Oct 31, 2021
af2b43c
feat(isUUID): add support for validation of version v1 and v2 (#1848)
theteladras Oct 31, 2021
01d3da3
feat(isMobilePhone): add Tajikistan tg-TJ locale (#1846)
mgnss Oct 31, 2021
fc0fefc
feat(isMobilePhone): add Bhutan dz-BT locale (#1770)
lakshayr003 Oct 31, 2021
5c2d69e
feat(isMobilePhone): regex for Burkina Faso fr-BF and Namibia en-NA l…
ZeeMangena Oct 23, 2021
c96d805
feat(isMobilePhone): add Maldives dv-MV locale
Prajwalrajbasnet Oct 25, 2021
ed60123
feat(isMobilePhone): add Tajikistan tg-TJ locale (#1846)
mgnss Oct 31, 2021
8627e48
feat(isMobilePhone): add Kiribati en-KI locale
c-tanner Oct 22, 2021
f7ff349
feat(isMobilePhone): add Frech Polynesia fr-PF locale
hereje Oct 16, 2021
0e5d5d4
feat(isMobilePhone): add Guyana en-GY locale
mfkrause Oct 12, 2021
26605f9
feat(isMobilePhone): add Turkmenistan tk-TM
husan-eshonqulov Oct 12, 2021
a3faa83
feat(isMobilePhone): add Botswana en-BW locale
mgndolan Oct 10, 2021
5b06703
feat(isMobilePhone): add Palestine ar-PS locale
brendan-c Oct 9, 2021
f17e220
feat(isMobilePhone): add El Salvador es-SV locale
hereje Oct 9, 2021
83cb7f8
chore: merge conflict clean-up
profnandaa Oct 31, 2021
45901ec
Merge pull request #1851 from validatorjs/chore/fix-merge-conflicts
profnandaa Oct 31, 2021
496fc8b
fix(rtrim): remove regex to prevent ReDOS attack (#1738)
tux-tn Nov 1, 2021
47ee5ad
13.7.0
profnandaa Nov 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Expand Up @@ -3,7 +3,7 @@ Add a descriptive title textbox above, e.g.
feat(validatorName): brief title of what has been done
-->

{{ briefly describe what you have done in this PR }}
<!--- briefly describe what you have done in this PR --->

## Checklist

Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Expand Up @@ -23,11 +23,8 @@ jobs:
run: npm install
- name: Run tests
run: npm test
- if: matrix.node-version == 14
name: Generate coverage file
run: npm run test:ci > coverage.lcov
- if: matrix.node-version == 14
name: Send coverage info to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.lcov
file: ./coverage/cobertura-coverage.xml
35 changes: 21 additions & 14 deletions README.md

Large diffs are not rendered by default.

48 changes: 23 additions & 25 deletions build-browser.js
@@ -1,34 +1,32 @@
/* eslint import/no-extraneous-dependencies: 0 */
import fs from 'fs';
import { rollup } from 'rollup';
import babel from 'rollup-plugin-babel';
import babelPresetEnv from '@babel/preset-env';
import pkg from './package.json';
import fs from "fs";
import { rollup } from "rollup";
import babel from "rollup-plugin-babel";
import babelPresetEnv from "@babel/preset-env";
import pkg from "./package.json";

rollup({
entry: 'src/index.js',
entry: "src/index.js",
plugins: [
babel({
presets: [[babelPresetEnv, { modules: false }]],
babelrc: false,
}),
],
}).then(bundle => (
bundle.write({
dest: 'validator.js',
format: 'umd',
moduleName: pkg.name,
banner: (
`/*!\n${
String(fs.readFileSync('./LICENSE'))
.trim()
.split('\n')
.map(l => ` * ${l}`)
.join('\n')
}\n */`
),
})
)).catch((e) => {
process.stderr.write(`${e.message}\n`);
process.exit(1);
});
})
.then((bundle) =>
bundle.write({
dest: "validator.js",
format: "umd",
moduleName: pkg.name,
banner: `/*!\n${String(fs.readFileSync("./LICENSE"))
.trim()
.split("\n")
.map((l) => ` * ${l}`)
.join("\n")}\n */`,
})
)
.catch((e) => {
process.stderr.write(`${e.message}\n`);
process.exit(1);
});
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -46,9 +46,10 @@
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.11.0",
"mocha": "^6.2.3",
"npm-run-all": "^4.1.5",
"nyc": "^14.1.0",
"rimraf": "^3.0.0",
"rollup": "^0.43.0",
"rollup": "^0.47.0",
"rollup-plugin-babel": "^4.0.1",
"uglify-js": "^3.0.19"
},
Expand All @@ -58,15 +59,14 @@
"clean:node": "rimraf index.js lib",
"clean:es": "rimraf es",
"clean:browser": "rimraf validator*.js",
"clean": "npm run clean:node && npm run clean:browser && npm run clean:es",
"clean": "run-p clean:*",
"minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/",
"build:browser": "node --require @babel/register build-browser && npm run minify",
"build:es": "babel src -d es --env-name=es",
"build:node": "babel src -d .",
"build": "npm run build:browser && npm run build:node && npm run build:es",
"build": "run-p build:*",
"pretest": "npm run build && npm run lint",
"test": "nyc mocha --require @babel/register --reporter dot",
"test:ci": "nyc report --reporter=text-lcov"
"test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot"
},
"engines": {
"node": ">= 0.10"
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Expand Up @@ -48,7 +48,7 @@ import isHSL from './lib/isHSL';

import isISRC from './lib/isISRC';

import isIBAN from './lib/isIBAN';
import isIBAN, { locales as ibanLocales } from './lib/isIBAN';
import isBIC from './lib/isBIC';

import isMD5 from './lib/isMD5';
Expand Down Expand Up @@ -90,6 +90,7 @@ import isISO8601 from './lib/isISO8601';
import isRFC3339 from './lib/isRFC3339';
import isISO31661Alpha2 from './lib/isISO31661Alpha2';
import isISO31661Alpha3 from './lib/isISO31661Alpha3';
import isISO4217 from './lib/isISO4217';

import isBase32 from './lib/isBase32';
import isBase58 from './lib/isBase58';
Expand Down Expand Up @@ -198,6 +199,7 @@ const validator = {
isRFC3339,
isISO31661Alpha2,
isISO31661Alpha3,
isISO4217,
isBase32,
isBase58,
isBase64,
Expand All @@ -222,6 +224,7 @@ const validator = {
isDate,
isLicensePlate,
isVAT,
ibanLocales,
};

export default validator;
6 changes: 5 additions & 1 deletion src/lib/alpha.js
Expand Up @@ -8,6 +8,7 @@ export const alpha = {
'el-GR': /^[Α-ώ]+$/i,
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i,
'fi-FI': /^[A-ZÅÄÖ]+$/i,
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
'nb-NO': /^[A-ZÆØÅ]+$/i,
Expand All @@ -30,6 +31,7 @@ export const alpha = {
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[א-ת]+$/,
fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i,
};

export const alphanumeric = {
Expand All @@ -41,6 +43,7 @@ export const alphanumeric = {
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
'el-GR': /^[0-9Α-ω]+$/i,
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
'fi-FI': /^[0-9A-ZÅÄÖ]+$/i,
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
Expand All @@ -63,6 +66,7 @@ export const alphanumeric = {
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[0-9א-ת]+$/,
fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i,
};

export const decimal = {
Expand Down Expand Up @@ -107,7 +111,7 @@ for (let locale, i = 0; i < farsiLocales.length; i++) {
export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
export const commaDecimal = [
'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR',
'id-ID', 'it-IT', 'ku-IQ', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT',
'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT',
'ru-RU', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN',
];

Expand Down
10 changes: 7 additions & 3 deletions src/lib/contains.js
Expand Up @@ -4,12 +4,16 @@ import merge from './util/merge';

const defaulContainsOptions = {
ignoreCase: false,
minOccurrences: 1,
};

export default function contains(str, elem, options) {
assertString(str);
options = merge(options, defaulContainsOptions);
return options.ignoreCase ?
str.toLowerCase().indexOf(toString(elem).toLowerCase()) >= 0 :
str.indexOf(toString(elem)) >= 0;

if (options.ignoreCase) {
return str.toLowerCase().split(toString(elem).toLowerCase()).length > options.minOccurrences;
}

return str.split(toString(elem)).length > options.minOccurrences;
}
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
13 changes: 11 additions & 2 deletions src/lib/isBoolean.js
@@ -1,6 +1,15 @@
import assertString from './util/assertString';

export default function isBoolean(str) {
const defaultOptions = { loose: false };
const strictBooleans = ['true', 'false', '1', '0'];
const looseBooleans = [...strictBooleans, 'yes', 'no'];

export default function isBoolean(str, options = defaultOptions) {
assertString(str);
return (['true', 'false', '1', '0'].indexOf(str) >= 0);

if (options.loose) {
return looseBooleans.includes(str.toLowerCase());
}

return strictBooleans.includes(str);
}
2 changes: 1 addition & 1 deletion src/lib/isCreditCard.js
@@ -1,7 +1,7 @@
import assertString from './util/assertString';

/* eslint-disable max-len */
const creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;
const creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
/* eslint-enable max-len */

export default function isCreditCard(str) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isDate.js
Expand Up @@ -7,7 +7,7 @@ const default_date_options = {
};

function isValidFormat(format) {
return /(^(y{4}|y{2})[\/-](m{1,2})[\/-](d{1,2})$)|(^(m{1,2})[\/-](d{1,2})[\/-]((y{4}|y{2})$))|(^(d{1,2})[\/-](m{1,2})[\/-]((y{4}|y{2})$))/gi.test(format);
return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format);
}

function zip(date, format) {
Expand Down
11 changes: 8 additions & 3 deletions src/lib/isEmail.js
Expand Up @@ -12,6 +12,7 @@ const default_email_options = {
require_tld: true,
blacklisted_chars: '',
ignore_max_length: false,
host_blacklist: [],
};

/* eslint-disable max-len */
Expand Down Expand Up @@ -92,10 +93,14 @@ export default function isEmail(str, options) {

const parts = str.split('@');
const domain = parts.pop();
let user = parts.join('@');

const lower_domain = domain.toLowerCase();

if (options.host_blacklist.includes(lower_domain)) {
return false;
}

let user = parts.join('@');

if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
/*
Previously we removed dots for gmail addresses before validating.
Expand All @@ -110,7 +115,7 @@ export default function isEmail(str, options) {
const username = user.split('+')[0];

// Dots are not included in gmail length restriction
if (!isByteLength(username.replace('.', ''), { min: 6, max: 30 })) {
if (!isByteLength(username.replace(/\./g, ''), { min: 6, max: 30 })) {
return false;
}

Expand Down
13 changes: 10 additions & 3 deletions src/lib/isFQDN.js
Expand Up @@ -6,6 +6,7 @@ const default_fqdn_options = {
allow_underscores: false,
allow_trailing_dot: false,
allow_numeric_tld: false,
allow_wildcard: false,
};

export default function isFQDN(str, options) {
Expand All @@ -16,6 +17,12 @@ export default function isFQDN(str, options) {
if (options.allow_trailing_dot && str[str.length - 1] === '.') {
str = str.substring(0, str.length - 1);
}

/* Remove the optional wildcard before checking validity */
if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
str = str.substring(2);
}

const parts = str.split('.');
const tld = parts[parts.length - 1];

Expand All @@ -25,12 +32,12 @@ export default function isFQDN(str, options) {
return false;
}

if (!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
if (!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
return false;
}

// disallow spaces && special characers
if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) {
// disallow spaces
if (/\s/.test(tld)) {
return false;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/isIBAN.js
Expand Up @@ -135,3 +135,5 @@ export default function isIBAN(str) {

return hasValidIbanFormat(str) && hasValidIbanChecksum(str);
}

export const locales = Object.keys(ibanRegexThroughCountryCode);
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;
7 changes: 3 additions & 4 deletions src/lib/isISO31661Alpha3.js
@@ -1,8 +1,7 @@
import assertString from './util/assertString';
import includes from './util/includes';

// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
const validISO31661Alpha3CountriesCodes = [
const validISO31661Alpha3CountriesCodes = new Set([
'AFG', 'ALA', 'ALB', 'DZA', 'ASM', 'AND', 'AGO', 'AIA', 'ATA', 'ATG', 'ARG', 'ARM', 'ABW', 'AUS', 'AUT', 'AZE',
'BHS', 'BHR', 'BGD', 'BRB', 'BLR', 'BEL', 'BLZ', 'BEN', 'BMU', 'BTN', 'BOL', 'BES', 'BIH', 'BWA', 'BVT', 'BRA',
'IOT', 'BRN', 'BGR', 'BFA', 'BDI', 'KHM', 'CMR', 'CAN', 'CPV', 'CYM', 'CAF', 'TCD', 'CHL', 'CHN', 'CXR', 'CCK',
Expand All @@ -19,9 +18,9 @@ const validISO31661Alpha3CountriesCodes = [
'ESP', 'LKA', 'SDN', 'SUR', 'SJM', 'SWZ', 'SWE', 'CHE', 'SYR', 'TWN', 'TJK', 'TZA', 'THA', 'TLS', 'TGO', 'TKL',
'TON', 'TTO', 'TUN', 'TUR', 'TKM', 'TCA', 'TUV', 'UGA', 'UKR', 'ARE', 'GBR', 'USA', 'UMI', 'URY', 'UZB', 'VUT',
'VEN', 'VNM', 'VGB', 'VIR', 'WLF', 'ESH', 'YEM', 'ZMB', 'ZWE',
];
]);

export default function isISO31661Alpha3(str) {
assertString(str);
return includes(validISO31661Alpha3CountriesCodes, str.toUpperCase());
return validISO31661Alpha3CountriesCodes.has(str.toUpperCase());
}