Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: update all tooling #2401

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "airbnb-base",
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
rubiin marked this conversation as resolved.
Show resolved Hide resolved
name: Run tests on Node.js ${{ matrix.node-version }}
steps:
- name: Setup Node.js ${{ matrix.node-version }}
Expand All @@ -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
Expand Down
14 changes: 5 additions & 9 deletions build-browser.js
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -62,15 +63,15 @@
"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:*",
"pretest": "npm run build && npm run lint",
"test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot --recursive"
},
"engines": {
"node": ">= 0.10"
"node": ">= 18"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion src/lib/alpha.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-misleading-character-class */
rubiin marked this conversation as resolved.
Show resolved Hide resolved
export const alpha = {
'en-US': /^[A-Z]+$/i,
'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i,
Expand Down Expand Up @@ -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++) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/isBase64.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] === '=');
}
2 changes: 1 addition & 1 deletion src/lib/isCreditCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib/isCurrency.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})*`,
Expand Down Expand Up @@ -53,7 +52,6 @@ function currencyRegex(options) {
return new RegExp(`^(?!-? )(?=.*\\d)${pattern}$`);
}


const default_currency_options = {
symbol: '$',
require_symbol: false,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isDataURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/lib/isEAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -60,7 +59,6 @@ function validateDisplayName(display_name) {
return true;
}


export default function isEmail(str, options) {
assertString(str);
options = merge(options, default_email_options);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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++) {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/isFloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 0 additions & 2 deletions src/lib/isHSL.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
8 changes: 4 additions & 4 deletions src/lib/isIBAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,8 +146,8 @@ function hasValidIbanFormat(str, options) {
}
}

return (isoCountryCodeInIbanRegexCodeObject) &&
ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
return (isoCountryCodeInIbanRegexCodeObject)
&& ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
}

/**
Expand All @@ -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, '');
Expand Down
3 changes: 0 additions & 3 deletions src/lib/isIMEI.js
Original file line number Diff line number Diff line change
@@ -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 || {};
Expand All @@ -17,7 +15,6 @@ export default function isIMEI(str, options) {
imeiRegex = imeiRegexWithHypens;
}


if (!imeiRegex.test(str)) {
return false;
}
Expand Down
20 changes: 10 additions & 10 deletions src/lib/isIP.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Loading