From 6d27507d4fc5c0ab40c9ce0dd5dd72c72095f587 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 10:25:49 +0100 Subject: [PATCH 01/24] chore: bump babel and eslint --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 7d505205e..658d8fe7f 100644 --- a/package.json +++ b/package.json @@ -36,15 +36,15 @@ "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.15.7", + "@babel/core": "^7.15.8", + "@babel/eslint-parser": "^7.15.8", + "@babel/preset-env": "^7.15.8", + "@babel/register": "^7.15.3", + "babel-plugin-add-module-exports": "^1.0.4", + "eslint": "^7.32.0", + "eslint-config-airbnb-base": "^14.2.1", + "eslint-plugin-import": "^2.25.2", "mocha": "^6.2.3", "npm-run-all": "^4.1.5", "nyc": "^14.1.0", From 2e2462664c684cfefcefd40a006972ded1e0750a Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 10:28:23 +0100 Subject: [PATCH 02/24] chore: update eslint config and fix no-else-return issues --- .eslintrc.json | 54 ++++++++++++++++++++++++--------------- src/lib/isIdentityCard.js | 8 +++--- src/lib/isIn.js | 6 +++-- src/lib/isLicensePlate.js | 3 ++- src/lib/isMobilePhone.js | 8 +++--- src/lib/isPostalCode.js | 3 ++- 6 files changed, 51 insertions(+), 31 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 285c41e15..b29e8c0b5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,9 +1,10 @@ { "extends": "airbnb-base", - "parser": "babel-eslint", + "parser": "@babel/eslint-parser", "parserOptions": { "ecmaVersion": 6, - "sourceType": "module" + "sourceType": "module", + "allowImportExportEverywhere": false }, "env": { "es6": true, @@ -12,29 +13,40 @@ "mocha": true }, "rules": { + "arrow-parens": 0, "camelcase": 0, + "comma-dangle": [ + 2, + { + "arrays": "always-multiline", + "objects": "always-multiline", + "imports": "always-multiline", + "exports": "always-multiline", + "functions": "never" + } + ], + "func-names": 0, + "implicit-arrow-linebreak": 0, + "linebreak-style": 0, + "newline-per-chained-call": 0, + "no-console": 0, + "no-misleading-character-class": 0, + "no-multiple-empty-lines": 0, "no-param-reassign": 0, + "no-prototype-builtins": 0, + "no-plusplus": [ + 2, + { + "allowForLoopAfterthoughts": true + } + ], + "no-restricted-globals": 0, + "no-restricted-syntax": [2, "DebuggerStatement", "LabeledStatement", "WithStatement"], + "no-useless-escape": 0, "one-var": 0, "one-var-declaration-per-line": 0, - "func-names": 0, - "no-console": 0, - "newline-per-chained-call": 0, + "operator-linebreak": 0, "prefer-const": 0, - "linebreak-style": 0, - "no-restricted-syntax": [2, "DebuggerStatement", "LabeledStatement", "WithStatement"], - "no-restricted-globals": 0, - "prefer-destructuring": 0, - "comma-dangle": [2, { - "arrays": "always-multiline", - "objects": "always-multiline", - "imports": "always-multiline", - "exports": "always-multiline", - "functions": "never" - }], - "no-plusplus": [2, { - "allowForLoopAfterthoughts": true - }], - "no-prototype-builtins": 0, - "no-useless-escape": 0 + "prefer-destructuring": 0 } } diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index 9dc1302ad..fe3a17739 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -286,8 +286,9 @@ const validators = { const xdata = new Date(yyyy, mm - 1, dd); if (xdata > new Date()) { return false; - // eslint-disable-next-line max-len - } else if ((xdata.getFullYear() === yyyy) && (xdata.getMonth() === mm - 1) && (xdata.getDate() === dd)) { + } + // eslint-disable-next-line max-len + if ((xdata.getFullYear() === yyyy) && (xdata.getMonth() === mm - 1) && (xdata.getDate() === dd)) { return true; } return false; @@ -396,7 +397,8 @@ 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..560de88e5 100644 --- a/src/lib/isIn.js +++ b/src/lib/isIn.js @@ -14,9 +14,11 @@ 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 d6b27a5ad..d9fbf52fe 100644 --- a/src/lib/isLicensePlate.js +++ b/src/lib/isLicensePlate.js @@ -19,7 +19,8 @@ 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/isMobilePhone.js b/src/lib/isMobilePhone.js index c70310ef7..6eb7c0f94 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -162,10 +162,12 @@ 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') { + } + // alias falsey locale as 'any' + if (!locale || locale === 'any') { for (const key in phones) { // istanbul ignore else if (phones.hasOwnProperty(key)) { diff --git a/src/lib/isPostalCode.js b/src/lib/isPostalCode.js index 7ef17abcf..069e542cf 100644 --- a/src/lib/isPostalCode.js +++ b/src/lib/isPostalCode.js @@ -79,7 +79,8 @@ 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 From 4658d17405628533da163be462f59b89d61d3a50 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 10:46:01 +0100 Subject: [PATCH 03/24] chore: make tests and coverage reports more verbose --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 658d8fe7f..82c3065b3 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "build:node": "babel src -d .", "build": "run-p build:*", "pretest": "npm run build && npm run lint", - "test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot" + "test": "nyc --reporter=lcov --reporter=text mocha --require @babel/register --reporter spec" }, "engines": { "node": ">= 0.10" From d1fac0272a30ae9ed8c126b9722c32261515b173 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 10:47:26 +0100 Subject: [PATCH 04/24] docs: bump copyright year --- LICENSE | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 4e49a3840..8d36754cd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2018 Chris O'Hara +Copyright (c) 2021 Chris O'Hara Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 2cf6505be..6368e8d11 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ Remember, validating can be troublesome sometimes. See [A list of articles about ## License (MIT) ``` -Copyright (c) 2018 Chris O'Hara +Copyright (c) 2021 Chris O'Hara Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From 3739722ba1ee1d99df0a4f032ffabf7c04b6deee Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 11:02:31 +0100 Subject: [PATCH 05/24] chore: bump actions versions in ci config --- .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 21686d855..7e0aeedde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: name: Run tests on Node.js ${{ matrix.node-version }} steps: - name: Setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2-beta + uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} check-latest: true @@ -24,7 +24,7 @@ jobs: - name: Run tests run: npm test - if: matrix.node-version == 14 - name: Send coverage info to Codecov + uses: codecov/codecov-action@v2 uses: codecov/codecov-action@v1 with: file: ./coverage/cobertura-coverage.xml From b77b7833c87ccad0c99d733c0ae9138c3bcd4fe9 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 11:04:25 +0100 Subject: [PATCH 06/24] chore: replace npm install and npm test with cit short --- .github/workflows/ci.yml | 4 +--- .github/workflows/npm-publish.yml | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e0aeedde..89e67c8ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,10 +19,8 @@ jobs: check-latest: true - name: Checkout repository uses: actions/checkout@v2 - - name: Install dependencies - run: npm install - name: Run tests - run: npm test + run: npm cit - if: matrix.node-version == 14 uses: codecov/codecov-action@v2 uses: codecov/codecov-action@v1 diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index b4b62f1b9..4c4554b39 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -14,10 +14,8 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Checkout Repository uses: actions/checkout@v2 - - name: Install Dependencies - run: npm install - name: Run Tests - run: npm test + run: npm cit - name: Publish Package to NPM Registry run: npm publish env: From 90b1287dd36479c5df2e0c420bc7d0740ad0b888 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 11:04:47 +0100 Subject: [PATCH 07/24] chore: send coverage info for all node versions in matrix --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89e67c8ea..2143992a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,7 @@ jobs: uses: actions/checkout@v2 - name: Run tests run: npm cit - - if: matrix.node-version == 14 + - name: Send coverage info to Codecov uses: codecov/codecov-action@v2 - uses: codecov/codecov-action@v1 with: file: ./coverage/cobertura-coverage.xml From d92d1671f032c49693cf0b2a787db5fbb77b432e Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 11:12:00 +0100 Subject: [PATCH 08/24] chore: fallback to npm install and test (package-lock is not commited) This reverts commit cf02e1cc514461b5ec19112efda5f587c2e29502. --- .github/workflows/ci.yml | 4 +++- .github/workflows/npm-publish.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2143992a6..c662d0f0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,10 @@ jobs: check-latest: true - name: Checkout repository uses: actions/checkout@v2 + - name: Install dependencies + run: npm install - name: Run tests - run: npm cit + run: npm test - name: Send coverage info to Codecov uses: codecov/codecov-action@v2 with: diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 4c4554b39..b4b62f1b9 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -14,8 +14,10 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Checkout Repository uses: actions/checkout@v2 + - name: Install Dependencies + run: npm install - name: Run Tests - run: npm cit + run: npm test - name: Publish Package to NPM Registry run: npm publish env: From d09030758d8bf1ec65b5cfa4cb39fe1734d4a5d6 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 11:57:47 +0100 Subject: [PATCH 09/24] chore: allow codecov to pick automatically the coverage file --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c662d0f0f..caccb44e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,4 @@ jobs: - name: Run tests run: npm test - name: Send coverage info to Codecov - uses: codecov/codecov-action@v2 - with: - file: ./coverage/cobertura-coverage.xml + uses: codecov/codecov-action@v2 \ No newline at end of file From 788591feba0e5a83ffae4e683d871ed3bb628d28 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 14:06:01 +0100 Subject: [PATCH 10/24] chore: add missing newline --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index caccb44e5..9810878f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,4 +24,4 @@ jobs: - name: Run tests run: npm test - name: Send coverage info to Codecov - uses: codecov/codecov-action@v2 \ No newline at end of file + uses: codecov/codecov-action@v2 From 09db1f55867eb5c8e42ba7b2b68066e802b0ad13 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 30 Oct 2021 17:54:10 +0100 Subject: [PATCH 11/24] chore: remove unneeded linebreak from license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 8d36754cd..7f2ea6820 100644 --- a/LICENSE +++ b/LICENSE @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file From 1679f35ea426b394efe1648aa8f4e7f4d9ac2091 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 30 Oct 2021 18:45:01 +0100 Subject: [PATCH 12/24] chore: reorder modules imports --- src/index.js | 330 +++++++++++++++++++++++---------------------------- 1 file changed, 150 insertions(+), 180 deletions(-) diff --git a/src/index.js b/src/index.js index b8ad651ee..28d7cc103 100644 --- a/src/index.js +++ b/src/index.js @@ -1,230 +1,200 @@ -import toDate from './lib/toDate'; -import toFloat from './lib/toFloat'; -import toInt from './lib/toInt'; -import toBoolean from './lib/toBoolean'; -import equals from './lib/equals'; +import blacklist from './lib/blacklist'; import contains from './lib/contains'; -import matches from './lib/matches'; - -import isEmail from './lib/isEmail'; -import isURL from './lib/isURL'; -import isMACAddress from './lib/isMACAddress'; -import isIP from './lib/isIP'; -import isIPRange from './lib/isIPRange'; -import isFQDN from './lib/isFQDN'; -import isDate from './lib/isDate'; - -import isBoolean from './lib/isBoolean'; -import isLocale from './lib/isLocale'; - +import equals from './lib/equals'; +import escape from './lib/escape'; +import isAfter from './lib/isAfter'; import isAlpha, { locales as isAlphaLocales } from './lib/isAlpha'; import isAlphanumeric, { locales as isAlphanumericLocales } from './lib/isAlphanumeric'; -import isNumeric from './lib/isNumeric'; -import isPassportNumber from './lib/isPassportNumber'; -import isPort from './lib/isPort'; -import isLowercase from './lib/isLowercase'; -import isUppercase from './lib/isUppercase'; - -import isIMEI from './lib/isIMEI'; - import isAscii from './lib/isAscii'; -import isFullWidth from './lib/isFullWidth'; -import isHalfWidth from './lib/isHalfWidth'; -import isVariableWidth from './lib/isVariableWidth'; -import isMultibyte from './lib/isMultibyte'; -import isSemVer from './lib/isSemVer'; -import isSurrogatePair from './lib/isSurrogatePair'; - -import isInt from './lib/isInt'; -import isFloat, { locales as isFloatLocales } from './lib/isFloat'; -import isDecimal from './lib/isDecimal'; -import isHexadecimal from './lib/isHexadecimal'; -import isOctal from './lib/isOctal'; -import isDivisibleBy from './lib/isDivisibleBy'; - -import isHexColor from './lib/isHexColor'; -import isRgbColor from './lib/isRgbColor'; -import isHSL from './lib/isHSL'; - -import isISRC from './lib/isISRC'; - -import isIBAN, { locales as ibanLocales } from './lib/isIBAN'; import isBIC from './lib/isBIC'; - -import isMD5 from './lib/isMD5'; -import isHash from './lib/isHash'; -import isJWT from './lib/isJWT'; - -import isJSON from './lib/isJSON'; -import isEmpty from './lib/isEmpty'; - -import isLength from './lib/isLength'; -import isByteLength from './lib/isByteLength'; - -import isUUID from './lib/isUUID'; -import isMongoId from './lib/isMongoId'; - -import isAfter from './lib/isAfter'; +import isBase32 from './lib/isBase32'; +import isBase58 from './lib/isBase58'; +import isBase64 from './lib/isBase64'; import isBefore from './lib/isBefore'; - -import isIn from './lib/isIn'; - +import isBoolean from './lib/isBoolean'; +import isBtcAddress from './lib/isBtcAddress'; +import isByteLength from './lib/isByteLength'; import isCreditCard from './lib/isCreditCard'; -import isIdentityCard from './lib/isIdentityCard'; - +import isCurrency from './lib/isCurrency'; +import isDataURI from './lib/isDataURI'; +import isDate from './lib/isDate'; +import isDecimal from './lib/isDecimal'; +import isDivisibleBy from './lib/isDivisibleBy'; import isEAN from './lib/isEAN'; -import isISIN from './lib/isISIN'; -import isISBN from './lib/isISBN'; -import isISSN from './lib/isISSN'; -import isTaxID from './lib/isTaxID'; - -import isMobilePhone, { locales as isMobilePhoneLocales } from './lib/isMobilePhone'; - +import isEmail from './lib/isEmail'; +import isEmpty from './lib/isEmpty'; import isEthereumAddress from './lib/isEthereumAddress'; - -import isCurrency from './lib/isCurrency'; - -import isBtcAddress from './lib/isBtcAddress'; - -import isISO8601 from './lib/isISO8601'; -import isRFC3339 from './lib/isRFC3339'; +import isFQDN from './lib/isFQDN'; +import isFloat, { locales as isFloatLocales } from './lib/isFloat'; +import isFullWidth from './lib/isFullWidth'; +import isHSL from './lib/isHSL'; +import isHalfWidth from './lib/isHalfWidth'; +import isHash from './lib/isHash'; +import isHexColor from './lib/isHexColor'; +import isHexadecimal from './lib/isHexadecimal'; +import isIBAN, { locales as ibanLocales } from './lib/isIBAN'; +import isIMEI from './lib/isIMEI'; +import isIP from './lib/isIP'; +import isIPRange from './lib/isIPRange'; +import isISBN from './lib/isISBN'; +import isISIN from './lib/isISIN'; 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'; -import isBase64 from './lib/isBase64'; -import isDataURI from './lib/isDataURI'; +import isISO8601 from './lib/isISO8601'; +import isISRC from './lib/isISRC'; +import isISSN from './lib/isISSN'; +import isIdentityCard from './lib/isIdentityCard'; +import isIn from './lib/isIn'; +import isInt from './lib/isInt'; +import isJSON from './lib/isJSON'; +import isJWT from './lib/isJWT'; +import isLatLong from './lib/isLatLong'; +import isLength from './lib/isLength'; +import isLicensePlate from './lib/isLicensePlate'; +import isLocale from './lib/isLocale'; +import isLowercase from './lib/isLowercase'; +import isMACAddress from './lib/isMACAddress'; +import isMD5 from './lib/isMD5'; import isMagnetURI from './lib/isMagnetURI'; - import isMimeType from './lib/isMimeType'; - -import isLatLong from './lib/isLatLong'; +import isMobilePhone, { locales as isMobilePhoneLocales } from './lib/isMobilePhone'; +import isMongoId from './lib/isMongoId'; +import isMultibyte from './lib/isMultibyte'; +import isNumeric from './lib/isNumeric'; +import isOctal from './lib/isOctal'; +import isPassportNumber from './lib/isPassportNumber'; +import isPort from './lib/isPort'; import isPostalCode, { locales as isPostalCodeLocales } from './lib/isPostalCode'; - +import isRFC3339 from './lib/isRFC3339'; +import isRgbColor from './lib/isRgbColor'; +import isSemVer from './lib/isSemVer'; +import isSlug from './lib/isSlug'; +import isStrongPassword from './lib/isStrongPassword'; +import isSurrogatePair from './lib/isSurrogatePair'; +import isTaxID from './lib/isTaxID'; +import isURL from './lib/isURL'; +import isUUID from './lib/isUUID'; +import isUppercase from './lib/isUppercase'; +import isVAT from './lib/isVAT'; +import isVariableWidth from './lib/isVariableWidth'; +import isWhitelisted from './lib/isWhitelisted'; import ltrim from './lib/ltrim'; +import matches from './lib/matches'; +import normalizeEmail from './lib/normalizeEmail'; import rtrim from './lib/rtrim'; +import stripLow from './lib/stripLow'; +import toBoolean from './lib/toBoolean'; +import toDate from './lib/toDate'; +import toFloat from './lib/toFloat'; +import toInt from './lib/toInt'; import trim from './lib/trim'; -import escape from './lib/escape'; import unescape from './lib/unescape'; -import stripLow from './lib/stripLow'; import whitelist from './lib/whitelist'; -import blacklist from './lib/blacklist'; -import isWhitelisted from './lib/isWhitelisted'; - -import normalizeEmail from './lib/normalizeEmail'; - -import isSlug from './lib/isSlug'; -import isLicensePlate from './lib/isLicensePlate'; -import isStrongPassword from './lib/isStrongPassword'; - -import isVAT from './lib/isVAT'; const version = '13.7.0'; const validator = { - version, - toDate, - toFloat, - toInt, - toBoolean, - equals, + blacklist, contains, - matches, - isEmail, - isURL, - isMACAddress, - isIP, - isIPRange, - isFQDN, - isBoolean, - isIBAN, - isBIC, + equals, + escape, + ibanLocales, + isAfter, isAlpha, isAlphaLocales, isAlphanumeric, isAlphanumericLocales, - isNumeric, - isPassportNumber, - isPort, - isLowercase, - isUppercase, isAscii, - isFullWidth, - isHalfWidth, - isVariableWidth, - isMultibyte, - isSemVer, - isSurrogatePair, - isInt, - isIMEI, - isFloat, - isFloatLocales, + isBIC, + isBase32, + isBase58, + isBase64, + isBefore, + isBoolean, + isBtcAddress, + isByteLength, + isCreditCard, + isCurrency, + isDataURI, + isDate, isDecimal, - isHexadecimal, - isOctal, isDivisibleBy, - isHexColor, - isRgbColor, + isEAN, + isEmail, + isEmpty, + isEthereumAddress, + isFQDN, + isFloat, + isFloatLocales, + isFullWidth, isHSL, - isISRC, - isMD5, + isHalfWidth, isHash, - isJWT, + isHexColor, + isHexadecimal, + isIBAN, + isIMEI, + isIP, + isIPRange, + isISBN, + isISIN, + isISO31661Alpha2, + isISO31661Alpha3, + isISO4217, + isISO8601, + isISRC, + isISSN, + isIdentityCard, + isIn, + isInt, isJSON, - isEmpty, + isJWT, + isLatLong, isLength, + isLicensePlate, isLocale, - isByteLength, - isUUID, - isMongoId, - isAfter, - isBefore, - isIn, - isCreditCard, - isIdentityCard, - isEAN, - isISIN, - isISBN, - isISSN, + isLowercase, + isMACAddress, + isMD5, + isMagnetURI, + isMimeType, isMobilePhone, isMobilePhoneLocales, + isMongoId, + isMultibyte, + isNumeric, + isOctal, + isPassportNumber, + isPort, isPostalCode, isPostalCodeLocales, - isEthereumAddress, - isCurrency, - isBtcAddress, - isISO8601, isRFC3339, - isISO31661Alpha2, - isISO31661Alpha3, - isISO4217, - isBase32, - isBase58, - isBase64, - isDataURI, - isMagnetURI, - isMimeType, - isLatLong, + isRgbColor, + isSemVer, + isSlug, + isStrongPassword, + isSurrogatePair, + isTaxID, + isURL, + isUUID, + isUppercase, + isVAT, + isVariableWidth, + isWhitelisted, ltrim, + matches, + normalizeEmail, rtrim, + stripLow, + toBoolean, + toDate, + toFloat, + toInt, trim, - escape, unescape, - stripLow, + version, whitelist, - blacklist, - isWhitelisted, - normalizeEmail, - toString, - isSlug, - isStrongPassword, - isTaxID, - isDate, - isLicensePlate, - isVAT, - ibanLocales, }; export default validator; From 70d835c64a67102e6b68506c7122b71004393231 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 30 Oct 2021 19:06:25 +0100 Subject: [PATCH 13/24] chore: modernize package bundling and allow esm tree shaking - Bump build dependencies - Use rollup for all outputs to reduce building time - Transpile to modern es2017 code for browsers supporting es modules using `@babel/preset-modules` - Give hints to javascript bundlers about source for es modules and browser script to use - Migrate from uglifyjs to terser (Allow minifying for modern browsers) --- .babelrc | 25 +------- build-browser.js | 32 ----------- package.json | 42 +++++++------- rollup.config.js | 144 +++++++++++++++++++++++++++++++++++++++++++++++ src/index.es.js | 102 +++++++++++++++++++++++++++++++++ 5 files changed, 269 insertions(+), 76 deletions(-) delete mode 100644 build-browser.js create mode 100644 rollup.config.js create mode 100644 src/index.es.js diff --git a/.babelrc b/.babelrc index 332bba6f9..0639bf764 100644 --- a/.babelrc +++ b/.babelrc @@ -1,24 +1,5 @@ { - "env": { - "es": { - "presets": [ - ["@babel/preset-env", { - "modules": false - }] - ] - }, - "development": { - "presets": [ - ["@babel/preset-env", { "targets": { "node": "0.10" } }] - ], - "plugins": [ - [ - "add-module-exports", - { - "addDefaultProperty": true - } - ] - ] - } - } + "presets": [ + "@babel/preset-env" + ] } \ No newline at end of file diff --git a/build-browser.js b/build-browser.js deleted file mode 100644 index c863bd399..000000000 --- a/build-browser.js +++ /dev/null @@ -1,32 +0,0 @@ -/* 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"; - -rollup({ - 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); - }); diff --git a/package.json b/package.json index 82c3065b3..65c7b14af 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,10 @@ "name": "validator", "description": "String validation and sanitization", "version": "13.7.0", + "source": "src/index.js", + "main": "index.js", + "module": "es/index.es.mjs", + "browser": "validator.js", "sideEffects": false, "homepage": "https://github.com/validatorjs/validator.js", "files": [ @@ -27,7 +31,6 @@ "contributors": [ "Anthony Nandaa (https://github.com/profnandaa)" ], - "main": "index.js", "bugs": { "url": "https://github.com/validatorjs/validator.js/issues" }, @@ -36,35 +39,30 @@ "url": "git+https://github.com/validatorjs/validator.js.git" }, "devDependencies": { - "@babel/cli": "^7.15.7", - "@babel/core": "^7.15.8", - "@babel/eslint-parser": "^7.15.8", - "@babel/preset-env": "^7.15.8", - "@babel/register": "^7.15.3", + "@babel/cli": "^7.16.0", + "@babel/core": "^7.16.0", + "@babel/eslint-parser": "^7.16.0", + "@babel/preset-env": "^7.16.0", + "@babel/preset-modules": "^0.1.5", + "@babel/register": "^7.16.0", + "@rollup/plugin-babel": "^5.3.0", "babel-plugin-add-module-exports": "^1.0.4", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-plugin-import": "^2.25.2", - "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", - "uglify-js": "^3.0.19" + "mocha": "^9.1.3", + "nyc": "^15.1.0", + "rimraf": "^3.0.2", + "rollup": "^2.58.3", + "rollup-plugin-license": "^2.6.0", + "rollup-plugin-terser": "^7.0.2" }, "scripts": { "lint": "eslint src test", "lint:fix": "eslint --fix src test", - "clean:node": "rimraf index.js lib", - "clean:es": "rimraf es", - "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:es": "babel src -d es --env-name=es", - "build:node": "babel src -d .", - "build": "run-p build:*", + "clean": "rimraf validator.js validator.min.js index.js lib es", + "prebuild": "npm run clean", + "build": "rollup -c", "pretest": "npm run build && npm run lint", "test": "nyc --reporter=lcov --reporter=text mocha --require @babel/register --reporter spec" }, diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 000000000..0386e2127 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,144 @@ +import path from 'path'; +import { babel, getBabelOutputPlugin } from '@rollup/plugin-babel'; +import license from 'rollup-plugin-license'; +import { terser } from 'rollup-plugin-terser'; +import pkg from './package.json'; + +const input = 'src/index.js'; +const esInput = 'src/index.es.js'; +export default [ + // commonjs (Node) + { + input, + output: { + format: 'cjs', + dir: '.', + name: pkg.name, + preserveModules: true, + exports: 'named', + plugins: [getBabelOutputPlugin({ + plugins: [ + ['add-module-exports', { + addDefaultProperty: true, + }], + ], + })], + }, + plugins: [ + babel({ + babelrc: false, + babelHelpers: 'inline', + presets: [ + ['@babel/preset-env', { + targets: { node: '0.10' }, + }], + ], + }), + ], + }, + // UMD Development (Node + Browsers) + { + input, + plugins: [ + babel({ + babelrc: false, + babelHelpers: 'bundled', + presets: [ + ['@babel/preset-env', { + targets: { node: '0.10' }, + }], + ], + }), + license({ + banner: { + commentStyle: 'ignored', + content: { + file: path.join(__dirname, 'LICENSE'), + encoding: 'utf-8', + }, + }, + }), + ], + output: { + format: 'umd', + file: pkg.browser, + name: pkg.name, + }, + }, + // UMD production (Node + Browsers) + { + input, + plugins: [ + babel({ + babelrc: false, + babelHelpers: 'bundled', + presets: [ + ['@babel/preset-env', { + targets: { node: '0.10' }, + }], + ], + }), + license({ + banner: { + commentStyle: 'ignored', + content: { + file: path.join(__dirname, 'LICENSE'), + encoding: 'utf-8', + }, + }, + }), + terser(), + ], + output: { + format: 'umd', + file: pkg.browser.replace('.js', '.min.js'), + name: pkg.name, + }, + }, + // ES6 + { + input: esInput, + plugins: [ + babel({ + babelrc: false, + babelHelpers: 'inline', + presets: [ + ['@babel/preset-modules', { + loose: true, + }], + ], + }), + ], + output: { + format: 'es', + dir: 'es', + name: pkg.name, + preserveModules: true, + esModule: true, + }, + }, + // ES6 mjs (Modern Browsers) + { + input: esInput, + plugins: [ + babel({ + babelrc: false, + babelHelpers: 'inline', + presets: [ + ['@babel/preset-modules', { + loose: true, + }], + ], + }), + terser({ ecma: 8, safari10: true }), + ], + output: { + format: 'es', + dir: 'es', + name: pkg.name, + preserveModules: true, + esModule: true, + entryFileNames: '[name].mjs', + }, + }, +]; diff --git a/src/index.es.js b/src/index.es.js new file mode 100644 index 000000000..feb15f87d --- /dev/null +++ b/src/index.es.js @@ -0,0 +1,102 @@ +export { default as blacklist } from './lib/blacklist'; +export { default as contains } from './lib/contains'; +export { default as equals } from './lib/equals'; +export { default as escape } from './lib/escape'; +export { default as isAfter } from './lib/isAfter'; +export { default as isAlpha } from './lib/isAlpha'; +export { default as isAlphanumeric } from './lib/isAlphanumeric'; +export { default as isAscii } from './lib/isAscii'; +export { default as isBIC } from './lib/isBIC'; +export { default as isBase32 } from './lib/isBase32'; +export { default as isBase58 } from './lib/isBase58'; +export { default as isBase64 } from './lib/isBase64'; +export { default as isBefore } from './lib/isBefore'; +export { default as isBoolean } from './lib/isBoolean'; +export { default as isBtcAddress } from './lib/isBtcAddress'; +export { default as isByteLength } from './lib/isByteLength'; +export { default as isCreditCard } from './lib/isCreditCard'; +export { default as isCurrency } from './lib/isCurrency'; +export { default as isDataURI } from './lib/isDataURI'; +export { default as isDate } from './lib/isDate'; +export { default as isDecimal } from './lib/isDecimal'; +export { default as isDivisibleBy } from './lib/isDivisibleBy'; +export { default as isEAN } from './lib/isEAN'; +export { default as isEmail } from './lib/isEmail'; +export { default as isEmpty } from './lib/isEmpty'; +export { default as isEthereumAddress } from './lib/isEthereumAddress'; +export { default as isFQDN } from './lib/isFQDN'; +export { default as isFloat } from './lib/isFloat'; +export { default as isFullWidth } from './lib/isFullWidth'; +export { default as isHSL } from './lib/isHSL'; +export { default as isHalfWidth } from './lib/isHalfWidth'; +export { default as isHash } from './lib/isHash'; +export { default as isHexColor } from './lib/isHexColor'; +export { default as isHexadecimal } from './lib/isHexadecimal'; +export { default as isIBAN } from './lib/isIBAN'; +export { default as isIMEI } from './lib/isIMEI'; +export { default as isIP } from './lib/isIP'; +export { default as isIPRange } from './lib/isIPRange'; +export { default as isISBN } from './lib/isISBN'; +export { default as isISIN } from './lib/isISIN'; +export { default as isISO31661Alpha2 } from './lib/isISO31661Alpha2'; +export { default as isISO31661Alpha3 } from './lib/isISO31661Alpha3'; +export { default as isISO4217 } from './lib/isISO4217'; +export { default as isISO8601 } from './lib/isISO8601'; +export { default as isISRC } from './lib/isISRC'; +export { default as isISSN } from './lib/isISSN'; +export { default as isIdentityCard } from './lib/isIdentityCard'; +export { default as isIn } from './lib/isIn'; +export { default as isInt } from './lib/isInt'; +export { default as isJSON } from './lib/isJSON'; +export { default as isJWT } from './lib/isJWT'; +export { default as isLatLong } from './lib/isLatLong'; +export { default as isLength } from './lib/isLength'; +export { default as isLicensePlate } from './lib/isLicensePlate'; +export { default as isLocale } from './lib/isLocale'; +export { default as isLowercase } from './lib/isLowercase'; +export { default as isMACAddress } from './lib/isMACAddress'; +export { default as isMD5 } from './lib/isMD5'; +export { default as isMagnetURI } from './lib/isMagnetURI'; +export { default as isMimeType } from './lib/isMimeType'; +export { default as isMobilePhone } from './lib/isMobilePhone'; +export { default as isMongoId } from './lib/isMongoId'; +export { default as isMultibyte } from './lib/isMultibyte'; +export { default as isNumeric } from './lib/isNumeric'; +export { default as isOctal } from './lib/isOctal'; +export { default as isPassportNumber } from './lib/isPassportNumber'; +export { default as isPort } from './lib/isPort'; +export { default as isPostalCode } from './lib/isPostalCode'; +export { default as isRFC3339 } from './lib/isRFC3339'; +export { default as isRgbColor } from './lib/isRgbColor'; +export { default as isSemVer } from './lib/isSemVer'; +export { default as isSlug } from './lib/isSlug'; +export { default as isStrongPassword } from './lib/isStrongPassword'; +export { default as isSurrogatePair } from './lib/isSurrogatePair'; +export { default as isTaxID } from './lib/isTaxID'; +export { default as isURL } from './lib/isURL'; +export { default as isUUID } from './lib/isUUID'; +export { default as isUppercase } from './lib/isUppercase'; +export { default as isVAT } from './lib/isVAT'; +export { default as isVariableWidth } from './lib/isVariableWidth'; +export { default as isWhitelisted } from './lib/isWhitelisted'; +export { default as ltrim } from './lib/ltrim'; +export { default as matches } from './lib/matches'; +export { default as normalizeEmail } from './lib/normalizeEmail'; +export { default as rtrim } from './lib/rtrim'; +export { default as stripLow } from './lib/stripLow'; +export { default as toBoolean } from './lib/toBoolean'; +export { default as toDate } from './lib/toDate'; +export { default as toFloat } from './lib/toFloat'; +export { default as toInt } from './lib/toInt'; +export { default as trim } from './lib/trim'; +export { default as unescape } from './lib/unescape'; +export { default as whitelist } from './lib/whitelist'; +export { locales as ibanLocales } from './lib/isIBAN'; +export { locales as isAlphaLocales } from './lib/isAlpha'; +export { locales as isAlphanumericLocales } from './lib/isAlphanumeric'; +export { locales as isFloatLocales } from './lib/isFloat'; +export { locales as isMobilePhoneLocales } from './lib/isMobilePhone'; +export { locales as isPostalCodeLocales } from './lib/isPostalCode'; +export { default } from './index'; +export const version = '13.6.0'; + From d553ac655f741dc1f7a0f369e1edf55b307a34f6 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 30 Oct 2021 22:34:44 +0100 Subject: [PATCH 14/24] chore: parse code in eslint as es8 --- .eslintrc.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index b29e8c0b5..2c647a1f0 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,12 +2,11 @@ "extends": "airbnb-base", "parser": "@babel/eslint-parser", "parserOptions": { - "ecmaVersion": 6, "sourceType": "module", "allowImportExportEverywhere": false }, "env": { - "es6": true, + "es2017": true, "browser": true, "node": true, "mocha": true From b5bcbaca7a7fd56ba94d9401bd7261aea7cfa8ea Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 30 Oct 2021 22:35:17 +0100 Subject: [PATCH 15/24] test: hide removed command from test error message --- test/client-side.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/client-side.js b/test/client-side.js index f0b5ca72c..d07adacdd 100644 --- a/test/client-side.js +++ b/test/client-side.js @@ -15,7 +15,7 @@ describe('Minified version', () => { }); it('should be up to date', () => { - assert.strictEqual(min.version, validator.version, 'Minified version mismatch. Run `make min`'); + assert.strictEqual(min.version, validator.version, 'Minified version mismatch.'); }); it('should validate strings', () => { From 132576b71ce5c7bdefa809e4719691ae81b69d11 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 30 Oct 2021 22:39:30 +0100 Subject: [PATCH 16/24] docs: add more details to usage description --- README.md | 64 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 6368e8d11..cf4afc0db 100644 --- a/README.md +++ b/README.md @@ -19,39 +19,40 @@ Passing anything other than a string will result in an error. ## Installation and Usage -### Server-side usage - Install the library with `npm install validator` -#### No ES6 +### CommonJS (Node.js) + +The library can be imported in node using the `require` syntax: ```javascript -var validator = require('validator'); +const validator = require('validator'); validator.isEmail('foo@bar.com'); //=> true ``` -#### ES6 +### ECMAScript modules + +The library can be used as an ECMAScript module with the `import` syntax: ```javascript import validator from 'validator'; -``` -Or, import only a subset of the library: - -```javascript -import isEmail from 'validator/lib/isEmail'; +validator.isEmail('foo@bar.com'); //=> true ``` -#### Tree-shakeable ES imports +You can also import only a subset of the library: + ```javascript -import isEmail from 'validator/es/lib/isEmail'; -``` +import { isEmail, isURL } from 'validator'; -### Client-side usage +isEmail('foo@bar.com'); //=> true +isURL('bar.com'); // => true +``` -The library can be loaded either as a standalone script, or through an [AMD][amd]-compatible loader +### UMD (Browsers) +The library can be loaded either as a standalone script, or through an [AMD][amd]-compatible loader: ```html @@ -66,10 +67,35 @@ The library can also be installed through [bower][bower] $ bower install validator-js ``` -CDN +### CDN + +For CDN, you can use [unpkg][unpkg] or [jsDelivr][jsdelivr] and if you need a specific version you can just replace `latest` with the version number. + +```html + + +``` + +```html + + +``` + +#### JavaScript modules +If you target browsers that [support](https://caniuse.com/es6-module) JavaScript module scripts (aka ES6 modules), you can import the library as a module from `unpkg` or `jsDelivr`. ```html - + + ``` ## Contributors @@ -204,7 +230,6 @@ In general, we follow the "fork-and-pull" Git workflow. 3. Work on your fork 1. Make your changes and additions - Most of your changes should be focused on `src/` and `test/` folders and/or `README.md`. - - Files such as `validator.js`, `validator.min.js` and files in `lib/` folder are autogenerated when running tests (`npm test`) and need not to be changed **manually**. 2. Change or add tests if needed 3. Run tests and make sure they pass 4. Add changes to README.md if needed @@ -269,6 +294,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [amd]: http://requirejs.org/docs/whyamd.html [bower]: http://bower.io/ - +[unpkg]: http://unpkg.com/ +[jsdelivr]: https://jsdelivr.com/ [mongoid]: http://docs.mongodb.org/manual/reference/object-id/ [ISIN]: https://en.wikipedia.org/wiki/International_Securities_Identification_Number From 68232b06c94219cbeb9bea9423222b4bd37e0deb Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 30 Oct 2021 22:42:21 +0100 Subject: [PATCH 17/24] chore: drop support of bower We are in 2021, bower was deprecated a long time ago --- README.md | 8 -------- bower.json | 19 ------------------- index.html | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 27 deletions(-) delete mode 100644 bower.json create mode 100644 index.html diff --git a/README.md b/README.md index cf4afc0db..8e9877083 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,6 @@ The library can be loaded either as a standalone script, or through an [AMD][amd validator.isEmail('foo@bar.com'); //=> true ``` - -The library can also be installed through [bower][bower] - -```bash -$ bower install validator-js -``` - ### CDN For CDN, you can use [unpkg][unpkg] or [jsDelivr][jsdelivr] and if you need a specific version you can just replace `latest` with the version number. @@ -293,7 +286,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [ci-image]: https://github.com/validatorjs/validator.js/workflows/CI/badge.svg?branch=master [amd]: http://requirejs.org/docs/whyamd.html -[bower]: http://bower.io/ [unpkg]: http://unpkg.com/ [jsdelivr]: https://jsdelivr.com/ [mongoid]: http://docs.mongodb.org/manual/reference/object-id/ diff --git a/bower.json b/bower.json deleted file mode 100644 index 427670cfc..000000000 --- a/bower.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "validator-js", - "main": "validator.js", - "homepage": "https://github.com/validatorjs/validator.js", - "authors": [ - "Chris O'Hara " - ], - "description": "String validation and sanitization", - "license": "MIT", - "ignore": [ - "**/.*", - "index.js", - "build*.js", - "package.json", - "node_modules", - "bower_components", - "test" - ] -} diff --git a/index.html b/index.html new file mode 100644 index 000000000..32d528231 --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + + Page Title + + + + + + \ No newline at end of file From 850f2d7cc72e1d65f09610c4cf7cd19d0be8f060 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Tue, 16 Nov 2021 00:47:33 +0100 Subject: [PATCH 18/24] style(isIdentityCard): remove Unnecessary else --- src/lib/isIdentityCard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index fe3a17739..6b5fe56d4 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -185,7 +185,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) => { From 24e038dcf2761306a3e621db22d569dd9eaf2668 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Tue, 16 Nov 2021 00:47:55 +0100 Subject: [PATCH 19/24] chore: bump dev dependencies --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 65c7b14af..0b8a83259 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "devDependencies": { "@babel/cli": "^7.16.0", "@babel/core": "^7.16.0", - "@babel/eslint-parser": "^7.16.0", + "@babel/eslint-parser": "^7.16.3", "@babel/preset-env": "^7.16.0", "@babel/preset-modules": "^0.1.5", "@babel/register": "^7.16.0", @@ -49,11 +49,11 @@ "babel-plugin-add-module-exports": "^1.0.4", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", - "eslint-plugin-import": "^2.25.2", + "eslint-plugin-import": "^2.25.3", "mocha": "^9.1.3", "nyc": "^15.1.0", "rimraf": "^3.0.2", - "rollup": "^2.58.3", + "rollup": "^2.60.0", "rollup-plugin-license": "^2.6.0", "rollup-plugin-terser": "^7.0.2" }, From 58e7ca3612c5cce526901d84508934f54d0f4fdd Mon Sep 17 00:00:00 2001 From: Sarhan Date: Tue, 16 Nov 2021 00:54:04 +0100 Subject: [PATCH 20/24] chore: bump version in es export --- src/index.es.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.es.js b/src/index.es.js index feb15f87d..47f5322f5 100644 --- a/src/index.es.js +++ b/src/index.es.js @@ -98,5 +98,5 @@ export { locales as isFloatLocales } from './lib/isFloat'; export { locales as isMobilePhoneLocales } from './lib/isMobilePhone'; export { locales as isPostalCodeLocales } from './lib/isPostalCode'; export { default } from './index'; -export const version = '13.6.0'; +export const version = '13.7.0'; From 668c7f56e837a498bcba4b4233cb1ecf0f119123 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Sat, 16 Oct 2021 11:01:56 +0100 Subject: [PATCH 21/24] chore: stop testing on EOL Node.js versions --- .github/workflows/ci.yml | 2 +- .github/workflows/npm-publish.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9810878f6..e5722885e 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: [14, 12, 10, 8, 6] + node-version: [16, 14, 12] name: Run tests on Node.js ${{ matrix.node-version }} steps: - name: Setup Node.js ${{ matrix.node-version }} diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index b4b62f1b9..482f34e57 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -6,10 +6,10 @@ jobs: publish: runs-on: ubuntu-20.04 steps: - - name: Setup Node.js 14 - uses: actions/setup-node@v2-beta + - name: Setup Node.js + uses: actions/setup-node@v2 with: - node-version: 14 + node-version: 16 check-latest: true registry-url: https://registry.npmjs.org/ - name: Checkout Repository From c2f3cfc588bf636887bd7cf0a2337bcee71234b0 Mon Sep 17 00:00:00 2001 From: Sarhan Date: Tue, 16 Nov 2021 01:34:04 +0100 Subject: [PATCH 22/24] chore: remove unrelated test page --- index.html | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 index.html diff --git a/index.html b/index.html deleted file mode 100644 index 32d528231..000000000 --- a/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - Page Title - - - - - - \ No newline at end of file From a22e76cd65a77a311e464395965720f12901105f Mon Sep 17 00:00:00 2001 From: Sarhan Date: Mon, 25 Apr 2022 00:01:30 +0100 Subject: [PATCH 23/24] style: fix eslint max-len issue - disable max-len for regexes --- src/lib/isCurrency.js | 4 +++- src/lib/isIP.js | 1 + src/lib/isRFC3339.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/isCurrency.js b/src/lib/isCurrency.js index 54b1f7c7c..81fc900f9 100755 --- a/src/lib/isCurrency.js +++ b/src/lib/isCurrency.js @@ -3,7 +3,9 @@ import assertString from './util/assertString'; 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}}`; }); + 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 ? '' : '?')}`, diff --git a/src/lib/isIP.js b/src/lib/isIP.js index 25856cae0..285df12c9 100644 --- a/src/lib/isIP.js +++ b/src/lib/isIP.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ import assertString from './util/assertString'; /** 11.3. Examples diff --git a/src/lib/isRFC3339.js b/src/lib/isRFC3339.js index 48b025e0f..6f106cd25 100644 --- a/src/lib/isRFC3339.js +++ b/src/lib/isRFC3339.js @@ -14,6 +14,7 @@ const timeSecFrac = /(\.[0-9]+)?/; const timeNumOffset = new RegExp(`[-+]${timeHour.source}:${timeMinute.source}`); const timeOffset = new RegExp(`([zZ]|${timeNumOffset.source})`); +// eslint-disable-next-line max-len const partialTime = new RegExp(`${timeHour.source}:${timeMinute.source}:${timeSecond.source}${timeSecFrac.source}`); const fullDate = new RegExp(`${dateFullYear.source}-${dateMonth.source}-${dateMDay.source}`); From 5de0bd30b2f8c262a6789b93d7b1129d323a85cb Mon Sep 17 00:00:00 2001 From: Sarhan Date: Mon, 25 Apr 2022 00:16:21 +0100 Subject: [PATCH 24/24] chore: bump dependencies --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 0b8a83259..f4e31b0a3 100644 --- a/package.json +++ b/package.json @@ -39,22 +39,22 @@ "url": "git+https://github.com/validatorjs/validator.js.git" }, "devDependencies": { - "@babel/cli": "^7.16.0", - "@babel/core": "^7.16.0", - "@babel/eslint-parser": "^7.16.3", - "@babel/preset-env": "^7.16.0", + "@babel/cli": "^7.17.6", + "@babel/core": "^7.17.9", + "@babel/eslint-parser": "^7.17.0", + "@babel/preset-env": "^7.16.11", "@babel/preset-modules": "^0.1.5", - "@babel/register": "^7.16.0", - "@rollup/plugin-babel": "^5.3.0", + "@babel/register": "^7.17.7", + "@rollup/plugin-babel": "^5.3.1", "babel-plugin-add-module-exports": "^1.0.4", "eslint": "^7.32.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-plugin-import": "^2.25.3", - "mocha": "^9.1.3", + "mocha": "^9.2.2", "nyc": "^15.1.0", "rimraf": "^3.0.2", - "rollup": "^2.60.0", - "rollup-plugin-license": "^2.6.0", + "rollup": "^2.70.2", + "rollup-plugin-license": "^2.7.0", "rollup-plugin-terser": "^7.0.2" }, "scripts": {