From cb84a819de9d6ac292bdc07a0c6f0231f4639cfe Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Fri, 10 May 2024 21:13:26 +0545 Subject: [PATCH 1/3] fix: update all tooling --- .eslintrc.json | 4 +- build-browser.js | 14 ++-- package.json | 31 ++++---- src/lib/alpha.js | 2 +- src/lib/isBase64.js | 6 +- src/lib/isCreditCard.js | 2 +- src/lib/isCurrency.js | 4 +- src/lib/isDataURI.js | 4 +- src/lib/isDate.js | 4 +- src/lib/isEAN.js | 1 - src/lib/isEmail.js | 18 +++-- src/lib/isFloat.js | 10 +-- src/lib/isHSL.js | 2 - src/lib/isIBAN.js | 8 +-- src/lib/isIMEI.js | 3 - src/lib/isIP.js | 20 +++--- src/lib/isIdentityCard.js | 16 ++--- src/lib/isIn.js | 4 +- src/lib/isLicensePlate.js | 32 ++++----- src/lib/isLocale.js | 10 +-- src/lib/isMobilePhone.js | 4 +- src/lib/isPassportNumber.js | 4 +- src/lib/isPostalCode.js | 2 +- src/lib/isRgbColor.js | 8 +-- src/lib/isTaxID.js | 74 +++++++++---------- src/lib/isURL.js | 1 - src/lib/isVAT.js | 137 ++++++++++++++++++------------------ src/lib/util/algorithms.js | 6 +- src/lib/util/includes.js | 2 +- test/clientSide.test.js | 3 +- test/exports.test.js | 3 +- test/sanitizers.test.js | 6 +- test/testFunctions.js | 9 ++- test/validators.test.js | 32 ++------- 34 files changed, 227 insertions(+), 259 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 285c41e15..cc8676048 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,6 @@ { "extends": "airbnb-base", - "parser": "babel-eslint", + "parser": "@babel/eslint-parser", "parserOptions": { "ecmaVersion": 6, "sourceType": "module" @@ -14,6 +14,8 @@ "rules": { "camelcase": 0, "no-param-reassign": 0, + "max-len": 0, + "default-param-last": 0, "one-var": 0, "one-var-declaration-per-line": 0, "func-names": 0, diff --git a/build-browser.js b/build-browser.js index c863bd399..6f40cdb14 100644 --- a/build-browser.js +++ b/build-browser.js @@ -1,24 +1,20 @@ /* 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 babel from "@rollup/plugin-babel"; import pkg from "./package.json"; rollup({ - entry: "src/index.js", + input: "src/index.js", plugins: [ - babel({ - presets: [[babelPresetEnv, { modules: false }]], - babelrc: false, - }), + babel() ], }) .then((bundle) => bundle.write({ - dest: "validator.js", + file: "validator.js", format: "umd", - moduleName: pkg.name, + name: pkg.name, banner: `/*!\n${String(fs.readFileSync("./LICENSE")) .trim() .split("\n") diff --git a/package.json b/package.json index 854657f4d..3f2fbf3d9 100644 --- a/package.json +++ b/package.json @@ -36,23 +36,24 @@ "url": "git+https://github.com/validatorjs/validator.js.git" }, "devDependencies": { - "@babel/cli": "^7.0.0", - "@babel/core": "^7.0.0", - "@babel/preset-env": "^7.0.0", - "@babel/register": "^7.0.0", - "babel-eslint": "^10.0.1", - "babel-plugin-add-module-exports": "^1.0.0", - "eslint": "^4.19.1", - "eslint-config-airbnb-base": "^12.1.0", - "eslint-plugin-import": "^2.11.0", + "@babel/cli": "^7.24.5", + "@babel/core": "^7.24.5", + "@babel/eslint-parser": "^7.24.5", + "@babel/node": "^7.23.9", + "@babel/preset-env": "^7.24.5", + "@babel/register": "^7.23.7", + "@rollup/plugin-babel": "^6.0.4", + "babel-plugin-add-module-exports": "^1.0.4", + "eslint": "^8.2.0", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-plugin-import": "^2.29.1", "mocha": "^6.2.3", "npm-run-all": "^4.1.5", - "nyc": "^14.1.0", - "rimraf": "^3.0.0", - "rollup": "^0.47.0", - "rollup-plugin-babel": "^4.0.1", + "nyc": "^14.1.1", + "rimraf": "^5.0.5", + "rollup": "^4.17.2", "timezone-mock": "^1.3.6", - "uglify-js": "^3.0.19" + "uglify-js": "^3.17.4" }, "scripts": { "lint": "eslint src test", @@ -62,7 +63,7 @@ "clean:browser": "rimraf validator*.js", "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:browser": "babel-node build-browser && npm run minify", "build:es": "babel src -d es --env-name=es", "build:node": "babel src -d .", "build": "run-p build:*", diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 8c37934ff..f4a176a68 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -1,3 +1,4 @@ +/* eslint-disable no-misleading-character-class */ export const alpha = { 'en-US': /^[A-Z]+$/i, 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i, @@ -86,7 +87,6 @@ export const decimal = { ar: '٫', }; - export const englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM']; for (let locale, i = 0; i < englishLocales.length; i++) { diff --git a/src/lib/isBase64.js b/src/lib/isBase64.js index 02dead0f4..d43f37113 100644 --- a/src/lib/isBase64.js +++ b/src/lib/isBase64.js @@ -22,7 +22,7 @@ export default function isBase64(str, options) { } const firstPaddingChar = str.indexOf('='); - return firstPaddingChar === -1 || - firstPaddingChar === len - 1 || - (firstPaddingChar === len - 2 && str[len - 1] === '='); + return firstPaddingChar === -1 + || firstPaddingChar === len - 1 + || (firstPaddingChar === len - 2 && str[len - 1] === '='); } diff --git a/src/lib/isCreditCard.js b/src/lib/isCreditCard.js index 938679d39..1115f61b0 100644 --- a/src/lib/isCreditCard.js +++ b/src/lib/isCreditCard.js @@ -34,7 +34,7 @@ export default function isCreditCard(card, options = {}) { } else if (provider && !(provider.toLowerCase() in cards)) { /* specific provider not in the list */ throw new Error(`${provider} is not a valid credit card provider.`); - } else if (!allCards.some(cardProvider => cardProvider.test(sanitized))) { + } else if (!allCards.some((cardProvider) => cardProvider.test(sanitized))) { // no specific provider return false; } diff --git a/src/lib/isCurrency.js b/src/lib/isCurrency.js index 54b1f7c7c..7a855be7d 100755 --- a/src/lib/isCurrency.js +++ b/src/lib/isCurrency.js @@ -5,8 +5,7 @@ function currencyRegex(options) { let decimal_digits = `\\d{${options.digits_after_decimal[0]}}`; options.digits_after_decimal.forEach((digit, index) => { if (index !== 0) decimal_digits = `${decimal_digits}|\\d{${digit}}`; }); - const symbol = - `(${options.symbol.replace(/\W/, m => `\\${m}`)})${(options.require_symbol ? '' : '?')}`, + const symbol = `(${options.symbol.replace(/\W/, (m) => `\\${m}`)})${(options.require_symbol ? '' : '?')}`, negative = '-?', whole_dollar_amount_without_sep = '[1-9]\\d*', whole_dollar_amount_with_sep = `[1-9]\\d{0,2}(\\${options.thousands_separator}\\d{3})*`, @@ -53,7 +52,6 @@ function currencyRegex(options) { return new RegExp(`^(?!-? )(?=.*\\d)${pattern}$`); } - const default_currency_options = { symbol: '$', require_symbol: false, diff --git a/src/lib/isDataURI.js b/src/lib/isDataURI.js index 506544807..412f6fc28 100644 --- a/src/lib/isDataURI.js +++ b/src/lib/isDataURI.js @@ -23,8 +23,8 @@ export default function isDataURI(str) { } for (let i = 0; i < attributes.length; i++) { if ( - !(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && - !validAttribute.test(attributes[i]) + !(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') + && !validAttribute.test(attributes[i]) ) { return false; } diff --git a/src/lib/isDate.js b/src/lib/isDate.js index dc69b3bc1..8b2083613 100644 --- a/src/lib/isDate.js +++ b/src/lib/isDate.js @@ -29,10 +29,10 @@ export default function isDate(input, options) { } if (typeof input === 'string' && isValidFormat(options.format)) { const formatDelimiter = options.delimiters - .find(delimiter => options.format.indexOf(delimiter) !== -1); + .find((delimiter) => options.format.indexOf(delimiter) !== -1); const dateDelimiter = options.strictMode ? formatDelimiter - : options.delimiters.find(delimiter => input.indexOf(delimiter) !== -1); + : options.delimiters.find((delimiter) => input.indexOf(delimiter) !== -1); const dateAndFormat = zip( input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter) diff --git a/src/lib/isEAN.js b/src/lib/isEAN.js index 968c385dd..48d27aafa 100644 --- a/src/lib/isEAN.js +++ b/src/lib/isEAN.js @@ -23,7 +23,6 @@ const LENGTH_EAN_8 = 8; const LENGTH_EAN_14 = 14; const validEanRegex = /^(\d{8}|\d{13}|\d{14})$/; - /** * Get position weight given: * EAN length and digit index/position diff --git a/src/lib/isEmail.js b/src/lib/isEmail.js index 12938765e..a5c96a113 100644 --- a/src/lib/isEmail.js +++ b/src/lib/isEmail.js @@ -50,8 +50,7 @@ function validateDisplayName(display_name) { } // the quotes in display name must start with character symbol \ - const all_start_with_back_slash = - display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length; + const all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length; if (!all_start_with_back_slash) { return false; } @@ -60,7 +59,6 @@ function validateDisplayName(display_name) { return true; } - export default function isEmail(str, options) { assertString(str); options = merge(options, default_email_options); @@ -134,8 +132,8 @@ export default function isEmail(str, options) { } if (options.ignore_max_length === false && ( - !isByteLength(user, { max: 64 }) || - !isByteLength(domain, { max: 254 })) + !isByteLength(user, { max: 64 }) + || !isByteLength(domain, { max: 254 })) ) { return false; } @@ -164,13 +162,13 @@ export default function isEmail(str, options) { if (user[0] === '"') { user = user.slice(1, user.length - 1); - return options.allow_utf8_local_part ? - quotedEmailUserUtf8.test(user) : - quotedEmailUser.test(user); + return options.allow_utf8_local_part + ? quotedEmailUserUtf8.test(user) + : quotedEmailUser.test(user); } - const pattern = options.allow_utf8_local_part ? - emailUserUtf8Part : emailUserPart; + const pattern = options.allow_utf8_local_part + ? emailUserUtf8Part : emailUserPart; const user_parts = user.split('.'); for (let i = 0; i < user_parts.length; i++) { diff --git a/src/lib/isFloat.js b/src/lib/isFloat.js index 643f9729f..58eeae919 100644 --- a/src/lib/isFloat.js +++ b/src/lib/isFloat.js @@ -9,11 +9,11 @@ export default function isFloat(str, options) { return false; } const value = parseFloat(str.replace(',', '.')); - return float.test(str) && - (!options.hasOwnProperty('min') || value >= options.min) && - (!options.hasOwnProperty('max') || value <= options.max) && - (!options.hasOwnProperty('lt') || value < options.lt) && - (!options.hasOwnProperty('gt') || value > options.gt); + return float.test(str) + && (!options.hasOwnProperty('min') || value >= options.min) + && (!options.hasOwnProperty('max') || value <= options.max) + && (!options.hasOwnProperty('lt') || value < options.lt) + && (!options.hasOwnProperty('gt') || value > options.gt); } export const locales = Object.keys(decimal); diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 05cb43962..8787a6619 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,10 +1,8 @@ import assertString from './util/assertString'; - const hslComma = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(,(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}(,((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?))?\)$/i; const hslSpace = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(\s(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s?(\/\s((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s?)?\)$/i; - export default function isHSL(str) { assertString(str); diff --git a/src/lib/isIBAN.js b/src/lib/isIBAN.js index 5edcf83a5..68b67f506 100644 --- a/src/lib/isIBAN.js +++ b/src/lib/isIBAN.js @@ -98,7 +98,7 @@ const ibanRegexThroughCountryCode = { function hasOnlyValidCountryCodes(countryCodeArray) { const countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray - .filter(countryCode => !(countryCode in ibanRegexThroughCountryCode)); + .filter((countryCode) => !(countryCode in ibanRegexThroughCountryCode)); if (countryCodeArrayFilteredWithObjectIbanCode.length > 0) { return false; @@ -146,8 +146,8 @@ function hasValidIbanFormat(str, options) { } } - return (isoCountryCodeInIbanRegexCodeObject) && - ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr); + return (isoCountryCodeInIbanRegexCodeObject) + && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr); } /** @@ -166,7 +166,7 @@ function hasValidIbanFormat(str, options) { function hasValidIbanChecksum(str) { const strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic const rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4); - const alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, char => char.charCodeAt(0) - 55); + const alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, (char) => char.charCodeAt(0) - 55); const remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g) .reduce((acc, value) => Number(acc + value) % 97, ''); diff --git a/src/lib/isIMEI.js b/src/lib/isIMEI.js index fb97d4924..6bd594c87 100644 --- a/src/lib/isIMEI.js +++ b/src/lib/isIMEI.js @@ -1,10 +1,8 @@ import assertString from './util/assertString'; - let imeiRegexWithoutHypens = /^[0-9]{15}$/; let imeiRegexWithHypens = /^\d{2}-\d{6}-\d{6}-\d{1}$/; - export default function isIMEI(str, options) { assertString(str); options = options || {}; @@ -17,7 +15,6 @@ export default function isIMEI(str, options) { imeiRegex = imeiRegexWithHypens; } - if (!imeiRegex.test(str)) { return false; } diff --git a/src/lib/isIP.js b/src/lib/isIP.js index 40ca19aec..9244938b2 100644 --- a/src/lib/isIP.js +++ b/src/lib/isIP.js @@ -33,16 +33,16 @@ const IPv4AddressFormat = `(${IPv4SegmentFormat}[.]){3}${IPv4SegmentFormat}`; const IPv4AddressRegExp = new RegExp(`^${IPv4AddressFormat}$`); const IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})'; -const IPv6AddressRegExp = new RegExp('^(' + - `(?:${IPv6SegmentFormat}:){7}(?:${IPv6SegmentFormat}|:)|` + - `(?:${IPv6SegmentFormat}:){6}(?:${IPv4AddressFormat}|:${IPv6SegmentFormat}|:)|` + - `(?:${IPv6SegmentFormat}:){5}(?::${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,2}|:)|` + - `(?:${IPv6SegmentFormat}:){4}(?:(:${IPv6SegmentFormat}){0,1}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,3}|:)|` + - `(?:${IPv6SegmentFormat}:){3}(?:(:${IPv6SegmentFormat}){0,2}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,4}|:)|` + - `(?:${IPv6SegmentFormat}:){2}(?:(:${IPv6SegmentFormat}){0,3}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,5}|:)|` + - `(?:${IPv6SegmentFormat}:){1}(?:(:${IPv6SegmentFormat}){0,4}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,6}|:)|` + - `(?::((?::${IPv6SegmentFormat}){0,5}:${IPv4AddressFormat}|(?::${IPv6SegmentFormat}){1,7}|:))` + - ')(%[0-9a-zA-Z-.:]{1,})?$'); +const IPv6AddressRegExp = new RegExp('^(' + + `(?:${IPv6SegmentFormat}:){7}(?:${IPv6SegmentFormat}|:)|` + + `(?:${IPv6SegmentFormat}:){6}(?:${IPv4AddressFormat}|:${IPv6SegmentFormat}|:)|` + + `(?:${IPv6SegmentFormat}:){5}(?::${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,2}|:)|` + + `(?:${IPv6SegmentFormat}:){4}(?:(:${IPv6SegmentFormat}){0,1}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,3}|:)|` + + `(?:${IPv6SegmentFormat}:){3}(?:(:${IPv6SegmentFormat}){0,2}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,4}|:)|` + + `(?:${IPv6SegmentFormat}:){2}(?:(:${IPv6SegmentFormat}){0,3}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,5}|:)|` + + `(?:${IPv6SegmentFormat}:){1}(?:(:${IPv6SegmentFormat}){0,4}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,6}|:)|` + + `(?::((?::${IPv6SegmentFormat}){0,5}:${IPv4AddressFormat}|(?::${IPv6SegmentFormat}){1,7}|:))` + + ')(%[0-9a-zA-Z-.:]{1,})?$'); export default function isIP(str, version = '') { assertString(str); diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 4734b7bd9..71a6da6c1 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -21,8 +21,7 @@ const validators = { if (str != null && str.length === 11 && isInt(str, { allow_leading_zeroes: true })) { const digits = str.split('').slice(0, -1); - const sum = digits.reduce((acc, digit, index) => - acc + (Number(digit) * weightOfDigits[index + 1]), 0); + const sum = digits.reduce((acc, digit, index) => acc + (Number(digit) * weightOfDigits[index + 1]), 0); const modulo = sum % 10; const lastDigit = Number(str.charAt(str.length - 1)); @@ -59,7 +58,7 @@ const validators = { } // validate the control digit - const number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, char => charsValue[char]); + const number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, (char) => charsValue[char]); return sanitized.endsWith(controlDigits[number % 23]); }, @@ -185,7 +184,7 @@ const validators = { const new_nic = /^[1-9]\d{11}$/i; if (str.length === 10 && old_nic.test(str)) return true; - else if (str.length === 12 && new_nic.test(str)) return true; + if (str.length === 12 && new_nic.test(str)) return true; return false; }, 'he-IL': (str) => { @@ -277,7 +276,7 @@ const validators = { const parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; - const checkAddressCode = addressCode => provincesAndCities.includes(addressCode); + const checkAddressCode = (addressCode) => provincesAndCities.includes(addressCode); const checkBirthDayCode = (birDayCode) => { const yyyy = parseInt(birDayCode.substring(0, 4), 10); @@ -287,7 +286,7 @@ const validators = { if (xdata > new Date()) { return false; // eslint-disable-next-line max-len - } else if ((xdata.getFullYear() === yyyy) && (xdata.getMonth() === mm - 1) && (xdata.getDate() === dd)) { + } if ((xdata.getFullYear() === yyyy) && (xdata.getMonth() === mm - 1) && (xdata.getDate() === dd)) { return true; } return false; @@ -305,8 +304,7 @@ const validators = { return parityBit[mod]; }; - const checkParityBit = idCardNo => getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase(); - + const checkParityBit = (idCardNo) => getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase(); const check15IdCardNo = (idCardNo) => { let check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo); @@ -427,7 +425,7 @@ export default function isIdentityCard(str, locale) { assertString(str); if (locale in validators) { return validators[locale](str); - } else if (locale === 'any') { + } if (locale === 'any') { for (const key in validators) { // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes // istanbul ignore else diff --git a/src/lib/isIn.js b/src/lib/isIn.js index e7f15804f..56ec76cdb 100644 --- a/src/lib/isIn.js +++ b/src/lib/isIn.js @@ -14,9 +14,9 @@ export default function isIn(str, options) { } } return array.indexOf(str) >= 0; - } else if (typeof options === 'object') { + } if (typeof options === 'object') { return options.hasOwnProperty(str); - } else if (options && typeof options.indexOf === 'function') { + } if (options && typeof options.indexOf === 'function') { return options.indexOf(str) >= 0; } return false; diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js index 8476f2f9e..d1b47c269 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -1,31 +1,25 @@ import assertString from './util/assertString'; const validators = { - 'cs-CZ': str => - /^(([ABCDEFHIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str), - 'de-DE': str => - /^((A|AA|AB|AC|AE|AH|AK|AM|AN|AÖ|AP|AS|AT|AU|AW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d{4})|(([EPVZ]-\d{5}))|(S A[A-Z]{2} \d{2})|(SP \d{2}-\d{2}))$/.test(str), - 'pt-BR': str => - /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str), - 'pt-PT': str => - /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str), - 'sq-AL': str => - /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str), - 'sv-SE': str => - /^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim()), - 'en-PK': str => /(^[A-Z]{2}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{3}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{4}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]((\s|-){0,1})[0-9]{4}((\s|-)[0-9]{2}){0,1}$)/.test(str.trim()), + 'cs-CZ': (str) => /^(([ABCDEFHIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str), + 'de-DE': (str) => /^((A|AA|AB|AC|AE|AH|AK|AM|AN|AÖ|AP|AS|AT|AU|AW|AZ|B|BA|BB|BC|BE|BF|BH|BI|BK|BL|BM|BN|BO|BÖ|BS|BT|BZ|C|CA|CB|CE|CO|CR|CW|D|DA|DD|DE|DH|DI|DL|DM|DN|DO|DU|DW|DZ|E|EA|EB|ED|EE|EF|EG|EH|EI|EL|EM|EN|ER|ES|EU|EW|F|FB|FD|FF|FG|FI|FL|FN|FO|FR|FS|FT|FÜ|FW|FZ|G|GA|GC|GD|GE|GF|GG|GI|GK|GL|GM|GN|GÖ|GP|GR|GS|GT|GÜ|GV|GW|GZ|H|HA|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VER|VIB|VIE|VIT|VOH|WAF|WAK|WAN|WAR|WAT|WBS|WDA|WEL|WEN|WER|WES|WHV|WIL|WIS|WIT|WIZ|WLG|WMS|WND|WOB|WOH|WOL|WOR|WOS|WRN|WSF|WST|WSW|WTL|WTM|WUG|WÜM|WUN|WUR|WZL|ZEL|ZIG)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str), + 'de-LI': (str) => /^FL[- ]?\d{1,5}[UZ]?$/.test(str), + 'en-IN': (str) => /^[A-Z]{2}[ -]?[0-9]{1,2}(?:[ -]?[A-Z])(?:[ -]?[A-Z]*)?[ -]?[0-9]{4}$/.test(str), + 'es-AR': (str) => /^(([A-Z]{2} ?[0-9]{3} ?[A-Z]{2})|([A-Z]{3} ?[0-9]{3}))$/.test(str), + 'fi-FI': (str) => /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str), + 'hu-HU': (str) => /^((((?!AAA)(([A-NPRSTVZWXY]{1})([A-PR-Z]{1})([A-HJ-NPR-Z]))|(A[ABC]I)|A[ABC]O|A[A-W]Q|BPI|BPO|UCO|UDO|XAO)-(?!000)\d{3})|(M\d{6})|((CK|DT|CD|HC|H[ABEFIKLMNPRSTVX]|MA|OT|R[A-Z]) \d{2}-\d{2})|(CD \d{3}-\d{3})|(C-(C|X) \d{4})|(X-(A|B|C) \d{4})|(([EPVZ]-\d{5}))|(S A[A-Z]{2} \d{2})|(SP \d{2}-\d{2}))$/.test(str), + 'pt-BR': (str) => /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str), + 'pt-PT': (str) => /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str), + 'sq-AL': (str) => /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str), + 'sv-SE': (str) => /^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim()), + 'en-PK': (str) => /(^[A-Z]{2}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{3}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{4}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]((\s|-){0,1})[0-9]{4}((\s|-)[0-9]{2}){0,1}$)/.test(str.trim()), }; export default function isLicensePlate(str, locale) { assertString(str); if (locale in validators) { return validators[locale](str); - } else if (locale === 'any') { + } if (locale === 'any') { for (const key in validators) { /* eslint guard-for-in: 0 */ const validator = validators[key]; diff --git a/src/lib/isLocale.js b/src/lib/isLocale.js index ec84c8fce..5a865d65f 100644 --- a/src/lib/isLocale.js +++ b/src/lib/isLocale.js @@ -57,17 +57,17 @@ const privateuse = '(x(-[A-Za-z0-9]{1,8})+)'; // otherwise be considered 'well-formed'. These tags are all valid, but // most are deprecated in favor of more modern subtags or subtag combination -const irregular = '((en-GB-oed)|(i-ami)|(i-bnn)|(i-default)|(i-enochian)|' + - '(i-hak)|(i-klingon)|(i-lux)|(i-mingo)|(i-navajo)|(i-pwn)|(i-tao)|' + - '(i-tay)|(i-tsu)|(sgn-BE-FR)|(sgn-BE-NL)|(sgn-CH-DE))'; +const irregular = '((en-GB-oed)|(i-ami)|(i-bnn)|(i-default)|(i-enochian)|' + + '(i-hak)|(i-klingon)|(i-lux)|(i-mingo)|(i-navajo)|(i-pwn)|(i-tao)|' + + '(i-tay)|(i-tsu)|(sgn-BE-FR)|(sgn-BE-NL)|(sgn-CH-DE))'; // regular tags match the 'langtag' production, but their subtags are not // extended language or variant subtags: their meaning is defined by // their registration and all of these are deprecated in favor of a more // modern subtag or sequence of subtags -const regular = '((art-lojban)|(cel-gaulish)|(no-bok)|(no-nyn)|(zh-guoyu)|' + - '(zh-hakka)|(zh-min)|(zh-min-nan)|(zh-xiang))'; +const regular = '((art-lojban)|(cel-gaulish)|(no-bok)|(no-nyn)|(zh-guoyu)|' + + '(zh-hakka)|(zh-min)|(zh-min-nan)|(zh-xiang))'; /* = irregular ; non-redundant tags registered diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 4d8192191..b42b249f3 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -189,10 +189,10 @@ export default function isMobilePhone(str, locale, options) { } return false; }); - } else if (locale in phones) { + } if (locale in phones) { return phones[locale].test(str); // alias falsey locale as 'any' - } else if (!locale || locale === 'any') { + } if (!locale || locale === 'any') { for (const key in phones) { // istanbul ignore else if (phones.hasOwnProperty(key)) { diff --git a/src/lib/isPassportNumber.js b/src/lib/isPassportNumber.js index c1803fb50..69e775441 100644 --- a/src/lib/isPassportNumber.js +++ b/src/lib/isPassportNumber.js @@ -82,6 +82,6 @@ export default function isPassportNumber(str, countryCode) { /** Remove All Whitespaces, Convert to UPPERCASE */ const normalizedStr = str.replace(/\s/g, '').toUpperCase(); - return (countryCode.toUpperCase() in passportRegexByCountryCode) && - passportRegexByCountryCode[countryCode].test(normalizedStr); + return (countryCode.toUpperCase() in passportRegexByCountryCode) + && passportRegexByCountryCode[countryCode].test(normalizedStr); } diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index 99cba290b..5098a41b6 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -81,7 +81,7 @@ export default function isPostalCode(str, locale) { assertString(str); if (locale in patterns) { return patterns[locale].test(str); - } else if (locale === 'any') { + } if (locale === 'any') { for (const key in patterns) { // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes // istanbul ignore else diff --git a/src/lib/isRgbColor.js b/src/lib/isRgbColor.js index 9458522ab..7a4650c08 100644 --- a/src/lib/isRgbColor.js +++ b/src/lib/isRgbColor.js @@ -12,8 +12,8 @@ export default function isRgbColor(str, includePercentValues = true) { return rgbColor.test(str) || rgbaColor.test(str); } - return rgbColor.test(str) || - rgbaColor.test(str) || - rgbColorPercent.test(str) || - rgbaColorPercent.test(str); + return rgbColor.test(str) + || rgbaColor.test(str) + || rgbColorPercent.test(str) + || rgbaColorPercent.test(str); } diff --git a/src/lib/isTaxID.js b/src/lib/isTaxID.js index d13229f69..49344209e 100644 --- a/src/lib/isTaxID.js +++ b/src/lib/isTaxID.js @@ -48,7 +48,7 @@ function bgBgCheck(tin) { if (!isDate(date, 'YYYY/MM/DD')) { return false; } // split digits into an array for further processing - const digits = tin.split('').map(a => parseInt(a, 10)); + const digits = tin.split('').map((a) => parseInt(a, 10)); // Calculate checksum by multiplying digits with fixed values const multip_lookup = [2, 4, 8, 5, 10, 9, 7, 3, 6]; @@ -77,14 +77,14 @@ function isCanadianSIN(input) { const digitsArray = input.split(''); const even = digitsArray .filter((_, idx) => idx % 2) - .map(i => Number(i) * 2) + .map((i) => Number(i) * 2) .join('') .split(''); const total = digitsArray .filter((_, idx) => !(idx % 2)) .concat(even) - .map(i => Number(i)) + .map((i) => Number(i)) .reduce((acc, cur) => acc + cur); return (total % 10 === 0); @@ -171,7 +171,7 @@ function deAtCheck(tin) { */ function deDeCheck(tin) { // Split digits into an array for further processing - const digits = tin.split('').map(a => parseInt(a, 10)); + const digits = tin.split('').map((a) => parseInt(a, 10)); // Fill array with strings of number positions let occurences = []; @@ -185,12 +185,12 @@ function deDeCheck(tin) { } // Remove digits with one occurence and test for only one duplicate/triplicate - occurences = occurences.filter(a => a.length > 1); + occurences = occurences.filter((a) => a.length > 1); if (occurences.length !== 2 && occurences.length !== 3) { return false; } // In case of triplicate value only two digits are allowed next to each other if (occurences[0].length === 3) { - const trip_locations = occurences[0].split('').map(a => parseInt(a, 10)); + const trip_locations = occurences[0].split('').map((a) => parseInt(a, 10)); let recurrent = 0; // Amount of neighbour occurences for (let i = 0; i < trip_locations.length - 1; i++) { if (trip_locations[i] + 1 === trip_locations[i + 1]) { @@ -250,7 +250,7 @@ function dkDkCheck(tin) { if (!isDate(date, 'YYYY/MM/DD')) { return false; } // Split digits into an array for further processing - const digits = tin.split('').map(a => parseInt(a, 10)); + const digits = tin.split('').map((a) => parseInt(a, 10)); let checksum = 0; let weight = 4; // Multiply by weight and add to checksum @@ -273,7 +273,7 @@ function dkDkCheck(tin) { */ function elCyCheck(tin) { // split digits into an array for further processing - const digits = tin.slice(0, 8).split('').map(a => parseInt(a, 10)); + const digits = tin.slice(0, 8).split('').map((a) => parseInt(a, 10)); let checksum = 0; // add digits in even places @@ -304,7 +304,7 @@ function elCyCheck(tin) { */ function elGrCheck(tin) { // split digits into an array for further processing - const digits = tin.split('').map(a => parseInt(a, 10)); + const digits = tin.split('').map((a) => parseInt(a, 10)); let checksum = 0; for (let i = 0; i < 8; i++) { @@ -325,7 +325,7 @@ function elGrCheck(tin) { * Verify TIN validity by calculating check (second to last) character */ function enIeCheck(tin) { - let checksum = algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 7).map(a => parseInt(a, 10)), 8); + let checksum = algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 7).map((a) => parseInt(a, 10)), 8); if (tin.length === 9 && tin[8] !== 'W') { checksum += (tin[8].charCodeAt(0) - 64) * 9; } @@ -466,7 +466,7 @@ function etEeCheck(tin) { if (!isDate(date, 'YYYY/MM/DD')) { return false; } // Split digits into an array for further processing - const digits = tin.split('').map(a => parseInt(a, 10)); + const digits = tin.split('').map((a) => parseInt(a, 10)); let checksum = 0; let weight = 1; // Multiply by weight and add to checksum @@ -596,7 +596,7 @@ function hrHrCheck(tin) { */ function huHuCheck(tin) { // split digits into an array for further processing - const digits = tin.split('').map(a => parseInt(a, 10)); + const digits = tin.split('').map((a) => parseInt(a, 10)); let checksum = 8; for (let i = 1; i < 9; i++) { @@ -842,7 +842,7 @@ function mtMtCheck(tin) { * Verify TIN validity by calculating check (last) digit (variant of MOD 11) */ function nlNlCheck(tin) { - return algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map(a => parseInt(a, 10)), 9) % 11 === parseInt(tin[8], 10); + return algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map((a) => parseInt(a, 10)), 9) % 11 === parseInt(tin[8], 10); } /* @@ -920,16 +920,16 @@ function ptBrCheck(tin) { sum = 0; if ( // Reject known invalid CPFs - tin === '11111111111' || - tin === '22222222222' || - tin === '33333333333' || - tin === '44444444444' || - tin === '55555555555' || - tin === '66666666666' || - tin === '77777777777' || - tin === '88888888888' || - tin === '99999999999' || - tin === '00000000000' + tin === '11111111111' + || tin === '22222222222' + || tin === '33333333333' + || tin === '44444444444' + || tin === '55555555555' + || tin === '66666666666' + || tin === '77777777777' + || tin === '88888888888' + || tin === '99999999999' + || tin === '00000000000' ) return false; for (let i = 1; i <= 9; i++) sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i); @@ -947,16 +947,16 @@ function ptBrCheck(tin) { } if ( // Reject know invalid CNPJs - tin === '00000000000000' || - tin === '11111111111111' || - tin === '22222222222222' || - tin === '33333333333333' || - tin === '44444444444444' || - tin === '55555555555555' || - tin === '66666666666666' || - tin === '77777777777777' || - tin === '88888888888888' || - tin === '99999999999999') { return false; } + tin === '00000000000000' + || tin === '11111111111111' + || tin === '22222222222222' + || tin === '33333333333333' + || tin === '44444444444444' + || tin === '55555555555555' + || tin === '66666666666666' + || tin === '77777777777777' + || tin === '88888888888888' + || tin === '99999999999999') { return false; } let length = tin.length - 2; let identifiers = tin.substring(0, length); @@ -993,7 +993,7 @@ function ptBrCheck(tin) { * Verify TIN validity by calculating check (last) digit (variant of MOD 11) */ function ptPtCheck(tin) { - let checksum = 11 - (algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map(a => parseInt(a, 10)), 9) % 11); + let checksum = 11 - (algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map((a) => parseInt(a, 10)), 9) % 11); if (checksum > 9) { return parseInt(tin[8], 10) === 0; } return checksum === parseInt(tin[8], 10); } @@ -1033,7 +1033,7 @@ function roRoCheck(tin) { } else if (!isDate(date, 'YYYY/MM/DD')) { return false; } // Calculate check digit - const digits = tin.split('').map(a => parseInt(a, 10)); + const digits = tin.split('').map((a) => parseInt(a, 10)); const multipliers = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9]; let checksum = 0; for (let i = 0; i < multipliers.length; i++) { @@ -1086,7 +1086,7 @@ function skSkCheck(tin) { * Verify TIN validity by calculating check (last) digit (variant of MOD 11) */ function slSiCheck(tin) { - let checksum = 11 - (algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 7).map(a => parseInt(a, 10)), 8) % 11); + let checksum = 11 - (algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 7).map((a) => parseInt(a, 10)), 8) % 11); if (checksum === 10) { return parseInt(tin[7], 10) === 0; } return checksum === parseInt(tin[7], 10); } @@ -1147,7 +1147,7 @@ function svSeCheck(tin) { */ function ukUaCheck(tin) { // Calculate check digit - const digits = tin.split('').map(a => parseInt(a, 10)); + const digits = tin.split('').map((a) => parseInt(a, 10)); const multipliers = [-1, 5, 7, 9, 4, 6, 10, 5, 7]; let checksum = 0; for (let i = 0; i < multipliers.length; i++) { diff --git a/src/lib/isURL.js b/src/lib/isURL.js index 3d2b1df3e..b05899780 100644 --- a/src/lib/isURL.js +++ b/src/lib/isURL.js @@ -17,7 +17,6 @@ validate_length - if set as false isURL will skip string length validation (IE m */ - const default_url_options = { protocols: ['http', 'https', 'ftp'], require_tld: true, diff --git a/src/lib/isVAT.js b/src/lib/isVAT.js index 50fcf52e0..5cebacc8d 100644 --- a/src/lib/isVAT.js +++ b/src/lib/isVAT.js @@ -22,14 +22,13 @@ const CH = (str) => { const hasValidCheckNumber = (digits) => { const lastDigit = digits.pop(); // used as check number const weights = [5, 4, 3, 2, 7, 6, 5, 4]; - const calculatedCheckNumber = (11 - (digits.reduce((acc, el, idx) => - acc + (el * weights[idx]), 0) % 11)) % 11; + const calculatedCheckNumber = (11 - (digits.reduce((acc, el, idx) => acc + (el * weights[idx]), 0) % 11)) % 11; return lastDigit === calculatedCheckNumber; }; // @see {@link https://www.estv.admin.ch/estv/de/home/mehrwertsteuer/uid/mwst-uid-nummer.html} - return /^(CHE[- ]?)?(\d{9}|(\d{3}\.\d{3}\.\d{3})|(\d{3} \d{3} \d{3})) ?(TVA|MWST|IVA)?$/.test(str) && hasValidCheckNumber((str.match(/\d/g).map(el => +el))); + return /^(CHE[- ]?)?(\d{9}|(\d{3}\.\d{3}\.\d{3})|(\d{3} \d{3} \d{3})) ?(TVA|MWST|IVA)?$/.test(str) && hasValidCheckNumber((str.match(/\d/g).map((el) => +el))); }; const PT = (str) => { @@ -40,7 +39,7 @@ const PT = (str) => { const tin = match[2]; - const checksum = 11 - (algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map(a => parseInt(a, 10)), 9) % 11); + const checksum = 11 - (algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map((a) => parseInt(a, 10)), 9) % 11); if (checksum > 9) { return parseInt(tin[8], 10) === 0; } @@ -51,82 +50,82 @@ export const vatMatchers = { /** * European Union VAT identification numbers */ - AT: str => /^(AT)?U\d{8}$/.test(str), - BE: str => /^(BE)?\d{10}$/.test(str), - BG: str => /^(BG)?\d{9,10}$/.test(str), - HR: str => /^(HR)?\d{11}$/.test(str), - CY: str => /^(CY)?\w{9}$/.test(str), - CZ: str => /^(CZ)?\d{8,10}$/.test(str), - DK: str => /^(DK)?\d{8}$/.test(str), - EE: str => /^(EE)?\d{9}$/.test(str), - FI: str => /^(FI)?\d{8}$/.test(str), - FR: str => /^(FR)?\w{2}\d{9}$/.test(str), - DE: str => /^(DE)?\d{9}$/.test(str), - EL: str => /^(EL)?\d{9}$/.test(str), - HU: str => /^(HU)?\d{8}$/.test(str), - IE: str => /^(IE)?\d{7}\w{1}(W)?$/.test(str), - IT: str => /^(IT)?\d{11}$/.test(str), - LV: str => /^(LV)?\d{11}$/.test(str), - LT: str => /^(LT)?\d{9,12}$/.test(str), - LU: str => /^(LU)?\d{8}$/.test(str), - MT: str => /^(MT)?\d{8}$/.test(str), - NL: str => /^(NL)?\d{9}B\d{2}$/.test(str), - PL: str => /^(PL)?(\d{10}|(\d{3}-\d{3}-\d{2}-\d{2})|(\d{3}-\d{2}-\d{2}-\d{3}))$/.test(str), + AT: (str) => /^(AT)?U\d{8}$/.test(str), + BE: (str) => /^(BE)?\d{10}$/.test(str), + BG: (str) => /^(BG)?\d{9,10}$/.test(str), + HR: (str) => /^(HR)?\d{11}$/.test(str), + CY: (str) => /^(CY)?\w{9}$/.test(str), + CZ: (str) => /^(CZ)?\d{8,10}$/.test(str), + DK: (str) => /^(DK)?\d{8}$/.test(str), + EE: (str) => /^(EE)?\d{9}$/.test(str), + FI: (str) => /^(FI)?\d{8}$/.test(str), + FR: (str) => /^(FR)?\w{2}\d{9}$/.test(str), + DE: (str) => /^(DE)?\d{9}$/.test(str), + EL: (str) => /^(EL)?\d{9}$/.test(str), + HU: (str) => /^(HU)?\d{8}$/.test(str), + IE: (str) => /^(IE)?\d{7}\w{1}(W)?$/.test(str), + IT: (str) => /^(IT)?\d{11}$/.test(str), + LV: (str) => /^(LV)?\d{11}$/.test(str), + LT: (str) => /^(LT)?\d{9,12}$/.test(str), + LU: (str) => /^(LU)?\d{8}$/.test(str), + MT: (str) => /^(MT)?\d{8}$/.test(str), + NL: (str) => /^(NL)?\d{9}B\d{2}$/.test(str), + PL: (str) => /^(PL)?(\d{10}|(\d{3}-\d{3}-\d{2}-\d{2})|(\d{3}-\d{2}-\d{2}-\d{3}))$/.test(str), PT, - RO: str => /^(RO)?\d{2,10}$/.test(str), - SK: str => /^(SK)?\d{10}$/.test(str), - SI: str => /^(SI)?\d{8}$/.test(str), - ES: str => /^(ES)?\w\d{7}[A-Z]$/.test(str), - SE: str => /^(SE)?\d{12}$/.test(str), + RO: (str) => /^(RO)?\d{2,10}$/.test(str), + SK: (str) => /^(SK)?\d{10}$/.test(str), + SI: (str) => /^(SI)?\d{8}$/.test(str), + ES: (str) => /^(ES)?\w\d{7}[A-Z]$/.test(str), + SE: (str) => /^(SE)?\d{12}$/.test(str), /** * VAT numbers of non-EU countries */ - AL: str => /^(AL)?\w{9}[A-Z]$/.test(str), - MK: str => /^(MK)?\d{13}$/.test(str), + AL: (str) => /^(AL)?\w{9}[A-Z]$/.test(str), + MK: (str) => /^(MK)?\d{13}$/.test(str), AU, - BY: str => /^(УНП )?\d{9}$/.test(str), - CA: str => /^(CA)?\d{9}$/.test(str), - IS: str => /^(IS)?\d{5,6}$/.test(str), - IN: str => /^(IN)?\d{15}$/.test(str), - ID: str => /^(ID)?(\d{15}|(\d{2}.\d{3}.\d{3}.\d{1}-\d{3}.\d{3}))$/.test(str), - IL: str => /^(IL)?\d{9}$/.test(str), - KZ: str => /^(KZ)?\d{12}$/.test(str), - NZ: str => /^(NZ)?\d{9}$/.test(str), - NG: str => /^(NG)?(\d{12}|(\d{8}-\d{4}))$/.test(str), - NO: str => /^(NO)?\d{9}MVA$/.test(str), - PH: str => /^(PH)?(\d{12}|\d{3} \d{3} \d{3} \d{3})$/.test(str), - RU: str => /^(RU)?(\d{10}|\d{12})$/.test(str), - SM: str => /^(SM)?\d{5}$/.test(str), - SA: str => /^(SA)?\d{15}$/.test(str), - RS: str => /^(RS)?\d{9}$/.test(str), + BY: (str) => /^(УНП )?\d{9}$/.test(str), + CA: (str) => /^(CA)?\d{9}$/.test(str), + IS: (str) => /^(IS)?\d{5,6}$/.test(str), + IN: (str) => /^(IN)?\d{15}$/.test(str), + ID: (str) => /^(ID)?(\d{15}|(\d{2}.\d{3}.\d{3}.\d{1}-\d{3}.\d{3}))$/.test(str), + IL: (str) => /^(IL)?\d{9}$/.test(str), + KZ: (str) => /^(KZ)?\d{12}$/.test(str), + NZ: (str) => /^(NZ)?\d{9}$/.test(str), + NG: (str) => /^(NG)?(\d{12}|(\d{8}-\d{4}))$/.test(str), + NO: (str) => /^(NO)?\d{9}MVA$/.test(str), + PH: (str) => /^(PH)?(\d{12}|\d{3} \d{3} \d{3} \d{3})$/.test(str), + RU: (str) => /^(RU)?(\d{10}|\d{12})$/.test(str), + SM: (str) => /^(SM)?\d{5}$/.test(str), + SA: (str) => /^(SA)?\d{15}$/.test(str), + RS: (str) => /^(RS)?\d{9}$/.test(str), CH, - TR: str => /^(TR)?\d{10}$/.test(str), - UA: str => /^(UA)?\d{12}$/.test(str), - GB: str => /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/.test(str), - UZ: str => /^(UZ)?\d{9}$/.test(str), + TR: (str) => /^(TR)?\d{10}$/.test(str), + UA: (str) => /^(UA)?\d{12}$/.test(str), + GB: (str) => /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/.test(str), + UZ: (str) => /^(UZ)?\d{9}$/.test(str), /** * VAT numbers of Latin American countries */ - AR: str => /^(AR)?\d{11}$/.test(str), - BO: str => /^(BO)?\d{7}$/.test(str), - BR: str => /^(BR)?((\d{2}.\d{3}.\d{3}\/\d{4}-\d{2})|(\d{3}.\d{3}.\d{3}-\d{2}))$/.test(str), - CL: str => /^(CL)?\d{8}-\d{1}$/.test(str), - CO: str => /^(CO)?\d{10}$/.test(str), - CR: str => /^(CR)?\d{9,12}$/.test(str), - EC: str => /^(EC)?\d{13}$/.test(str), - SV: str => /^(SV)?\d{4}-\d{6}-\d{3}-\d{1}$/.test(str), - GT: str => /^(GT)?\d{7}-\d{1}$/.test(str), - HN: str => /^(HN)?$/.test(str), - MX: str => /^(MX)?\w{3,4}\d{6}\w{3}$/.test(str), - NI: str => /^(NI)?\d{3}-\d{6}-\d{4}\w{1}$/.test(str), - PA: str => /^(PA)?$/.test(str), - PY: str => /^(PY)?\d{6,8}-\d{1}$/.test(str), - PE: str => /^(PE)?\d{11}$/.test(str), - DO: str => /^(DO)?(\d{11}|(\d{3}-\d{7}-\d{1})|[1,4,5]{1}\d{8}|([1,4,5]{1})-\d{2}-\d{5}-\d{1})$/.test(str), - UY: str => /^(UY)?\d{12}$/.test(str), - VE: str => /^(VE)?[J,G,V,E]{1}-(\d{9}|(\d{8}-\d{1}))$/.test(str), + AR: (str) => /^(AR)?\d{11}$/.test(str), + BO: (str) => /^(BO)?\d{7}$/.test(str), + BR: (str) => /^(BR)?((\d{2}.\d{3}.\d{3}\/\d{4}-\d{2})|(\d{3}.\d{3}.\d{3}-\d{2}))$/.test(str), + CL: (str) => /^(CL)?\d{8}-\d{1}$/.test(str), + CO: (str) => /^(CO)?\d{10}$/.test(str), + CR: (str) => /^(CR)?\d{9,12}$/.test(str), + EC: (str) => /^(EC)?\d{13}$/.test(str), + SV: (str) => /^(SV)?\d{4}-\d{6}-\d{3}-\d{1}$/.test(str), + GT: (str) => /^(GT)?\d{7}-\d{1}$/.test(str), + HN: (str) => /^(HN)?$/.test(str), + MX: (str) => /^(MX)?\w{3,4}\d{6}\w{3}$/.test(str), + NI: (str) => /^(NI)?\d{3}-\d{6}-\d{4}\w{1}$/.test(str), + PA: (str) => /^(PA)?$/.test(str), + PY: (str) => /^(PY)?\d{6,8}-\d{1}$/.test(str), + PE: (str) => /^(PE)?\d{11}$/.test(str), + DO: (str) => /^(DO)?(\d{11}|(\d{3}-\d{7}-\d{1})|[1,4,5]{1}\d{8}|([1,4,5]{1})-\d{2}-\d{5}-\d{1})$/.test(str), + UY: (str) => /^(UY)?\d{12}$/.test(str), + VE: (str) => /^(VE)?[J,G,V,E]{1}-(\d{9}|(\d{8}-\d{1}))$/.test(str), }; export default function isVAT(str, countryCode) { diff --git a/src/lib/util/algorithms.js b/src/lib/util/algorithms.js index 4ac1f2784..d5eee6390 100644 --- a/src/lib/util/algorithms.js +++ b/src/lib/util/algorithms.js @@ -11,8 +11,8 @@ export function iso7064Check(str) { let checkvalue = 10; for (let i = 0; i < str.length - 1; i++) { - checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? (10 * 2) % 11 : - (((parseInt(str[i], 10) + checkvalue) % 10) * 2) % 11; + checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? (10 * 2) % 11 + : (((parseInt(str[i], 10) + checkvalue) % 10) * 2) % 11; } checkvalue = checkvalue === 1 ? 0 : 11 - checkvalue; return checkvalue === parseInt(str[10], 10); @@ -31,7 +31,7 @@ export function luhnCheck(str) { const product = parseInt(str[i], 10) * 2; if (product > 9) { // sum digits of product and add to checksum - checksum += product.toString().split('').map(a => parseInt(a, 10)).reduce((a, b) => a + b, 0); + checksum += product.toString().split('').map((a) => parseInt(a, 10)).reduce((a, b) => a + b, 0); } else { checksum += product; } diff --git a/src/lib/util/includes.js b/src/lib/util/includes.js index 70ace8857..e039dafc8 100644 --- a/src/lib/util/includes.js +++ b/src/lib/util/includes.js @@ -1,3 +1,3 @@ -const includes = (arr, val) => arr.some(arrVal => val === arrVal); +const includes = (arr, val) => arr.some((arrVal) => val === arrVal); export default includes; diff --git a/test/clientSide.test.js b/test/clientSide.test.js index f0b5ca72c..e62761648 100644 --- a/test/clientSide.test.js +++ b/test/clientSide.test.js @@ -8,7 +8,8 @@ describe('Minified version', () => { if ({}.hasOwnProperty.call(validator, key)) { assert.strictEqual( typeof validator[key], - typeof min[key], `Minified version did not export ${key}` + typeof min[key], + `Minified version did not export ${key}` ); } } diff --git a/test/exports.test.js b/test/exports.test.js index 0bff532ab..bbbade449 100644 --- a/test/exports.test.js +++ b/test/exports.test.js @@ -21,7 +21,8 @@ describe('Exports', () => { it('should export the version number', () => { /* eslint-disable global-require */ assert.strictEqual( - validator.version, require('../package.json').version, + validator.version, + require('../package.json').version, 'Version number mismatch in "package.json" vs. "validator.js"' ); /* eslint-enable global-require */ diff --git a/test/sanitizers.test.js b/test/sanitizers.test.js index ecb0e128f..d28a374b4 100644 --- a/test/sanitizers.test.js +++ b/test/sanitizers.test.js @@ -17,7 +17,10 @@ function test(options) { if (result !== expected) { let warning = format( 'validator.%s(%s) returned "%s" but should have returned "%s"', - options.sanitizer, args.join(', '), result, expected + options.sanitizer, + args.join(', '), + result, + expected ); throw new Error(warning); @@ -107,7 +110,6 @@ describe('Sanitizers', () => { expect: { '\\S01010020100001': '01010020100001' }, }); - test({ sanitizer: 'rtrim', args: ['01'], diff --git a/test/testFunctions.js b/test/testFunctions.js index bcd7c15b0..ed109f37e 100644 --- a/test/testFunctions.js +++ b/test/testFunctions.js @@ -16,7 +16,8 @@ export default function test(options) { } catch (err) { const warning = format( 'validator.%s(%s) passed but should error', - options.validator, args.join(', ') + options.validator, + args.join(', ') ); throw new Error(warning); @@ -31,7 +32,8 @@ export default function test(options) { if (validator[options.validator](...args) !== true) { const warning = format( 'validator.%s(%s) failed but should have passed', - options.validator, args.join(', ') + options.validator, + args.join(', ') ); throw new Error(warning); @@ -46,7 +48,8 @@ export default function test(options) { if (validator[options.validator](...args) !== false) { const warning = format( 'validator.%s(%s) passed but should have failed', - options.validator, args.join(', ') + options.validator, + args.join(', ') ); throw new Error(warning); diff --git a/test/validators.test.js b/test/validators.test.js index 6b603ff1b..bd2b02e6a 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -275,7 +275,6 @@ describe('Validators', () => { }); }); - it('should validate really long emails if ignore_max_length is set', () => { test({ validator: 'isEmail', @@ -480,7 +479,6 @@ describe('Validators', () => { }); }); - it('should validate URLs with any protocol', () => { test({ validator: 'isURL', @@ -2909,7 +2907,6 @@ describe('Validators', () => { ], }); - test({ validator: 'isPassportNumber', args: ['ID'], @@ -4028,7 +4025,6 @@ describe('Validators', () => { }); }); - it('should validate imei strings', () => { test({ validator: 'isIMEI', @@ -4048,7 +4044,6 @@ describe('Validators', () => { }); }); - it('should validate imei strings with hyphens', () => { test({ validator: 'isIMEI', @@ -4069,7 +4064,6 @@ describe('Validators', () => { }); }); - it('should validate uppercase strings', () => { test({ validator: 'isUppercase', @@ -5557,7 +5551,6 @@ describe('Validators', () => { }); }); - it('should validate credit cards without a proper provider', () => { test({ validator: 'isCreditCard', @@ -5573,7 +5566,6 @@ describe('Validators', () => { }); }); - it('should validate AmEx provided credit cards', () => { test({ validator: 'isCreditCard', @@ -5609,7 +5601,6 @@ describe('Validators', () => { }); }); - it('should validate Diners Club provided credit cards', () => { test({ validator: 'isCreditCard', @@ -5719,7 +5710,6 @@ describe('Validators', () => { }); }); - it('should validate Mastercard provided credit cards', () => { test({ validator: 'isCreditCard', @@ -5755,7 +5745,6 @@ describe('Validators', () => { }); }); - it('should validate Union Pay provided credit cards', () => { test({ validator: 'isCreditCard', @@ -5790,7 +5779,6 @@ describe('Validators', () => { }); }); - it('should validate Visa provided credit cards', () => { test({ validator: 'isCreditCard', @@ -5826,7 +5814,6 @@ describe('Validators', () => { }); }); - it('should validate identity cards', () => { const fixtures = [ { @@ -6636,13 +6623,13 @@ describe('Validators', () => { 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4=', 'Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIHBvcnRhLg==', 'U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==', - 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuMPNS1Ufof9EW/M98FNw' + - 'UAKrwflsqVxaxQjBQnHQmiI7Vac40t8x7pIb8gLGV6wL7sBTJiPovJ0V7y7oc0Ye' + - 'rhKh0Rm4skP2z/jHwwZICgGzBvA0rH8xlhUiTvcwDCJ0kc+fh35hNt8srZQM4619' + - 'FTgB66Xmp4EtVyhpQV+t02g6NzK72oZI0vnAvqhpkxLeLiMCyrI416wHm5Tkukhx' + - 'QmcL2a6hNOyu0ixX/x2kSFXApEnVrJ+/IxGyfyw8kf4N2IZpW5nEP847lpfj0SZZ' + - 'Fwrd1mnfnDbYohX2zRptLy2ZUn06Qo9pkG5ntvFEPo9bfZeULtjYzIl6K8gJ2uGZ' + - 'HQIDAQAB', + 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuMPNS1Ufof9EW/M98FNw' + + 'UAKrwflsqVxaxQjBQnHQmiI7Vac40t8x7pIb8gLGV6wL7sBTJiPovJ0V7y7oc0Ye' + + 'rhKh0Rm4skP2z/jHwwZICgGzBvA0rH8xlhUiTvcwDCJ0kc+fh35hNt8srZQM4619' + + 'FTgB66Xmp4EtVyhpQV+t02g6NzK72oZI0vnAvqhpkxLeLiMCyrI416wHm5Tkukhx' + + 'QmcL2a6hNOyu0ixX/x2kSFXApEnVrJ+/IxGyfyw8kf4N2IZpW5nEP847lpfj0SZZ' + + 'Fwrd1mnfnDbYohX2zRptLy2ZUn06Qo9pkG5ntvFEPo9bfZeULtjYzIl6K8gJ2uGZ' + + 'HQIDAQAB', ], invalid: [ '12345', @@ -10189,7 +10176,6 @@ describe('Validators', () => { args: [], }); - it('should error on invalid locale', () => { test({ validator: 'isMobilePhone', @@ -11659,7 +11645,6 @@ describe('Validators', () => { /* eslint-enable max-len */ }); - it('should validate magnetURI', () => { /* eslint-disable max-len */ test({ @@ -11693,7 +11678,6 @@ describe('Validators', () => { /* eslint-enable max-len */ }); - it('should validate LatLong', () => { test({ validator: 'isLatLong', @@ -12390,7 +12374,6 @@ describe('Validators', () => { }); }); - it('should validate ISO6346 shipping containerID', () => { test({ validator: 'isISO6346', @@ -13023,7 +13006,6 @@ describe('Validators', () => { }); }); - it('should validate slug', () => { test({ validator: 'isSlug', From 5ef725d90589aaeb072e5861215e48a0ff92b034 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Fri, 10 May 2024 21:17:36 +0545 Subject: [PATCH 2/3] fix: remove older node versions --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4e532908..52941c7f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - node-version: [20, 18, 16, 14, 12, 10, 8, 6] + node-version: [20, 18] name: Run tests on Node.js ${{ matrix.node-version }} steps: - name: Setup Node.js ${{ matrix.node-version }} @@ -20,7 +20,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - name: Install dependencies - run: npm install --legacy-peer-deps + run: npm install - name: Run tests run: npm test - if: matrix.node-version == 20 From 9b79e72b4acfa7ae167e932f62ed323a9d7a62ba Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Fri, 17 May 2024 21:00:19 +0545 Subject: [PATCH 3/3] fix: Update package.json to support latest node versions only --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f2fbf3d9..f8c75461e 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot --recursive" }, "engines": { - "node": ">= 0.10" + "node": ">= 18" }, "license": "MIT" }