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

maintenance: release 2308 prep - v13.11.0 #2252

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
78f25ba
feat(isFreightContainerID): add new validator (#2144)
songyuew Feb 8, 2023
ecce35f
feat(isMobilePhone): add locale so-SO (#2175)
ohersi Feb 8, 2023
7cda875
feat(isMobilePhone): add fr-CF locale (#2176)
cheboi Feb 8, 2023
0188a95
fix(docs): add missing locale fr-CF (#2178)
profnandaa Feb 8, 2023
43803c0
chore: add note about providing a reference in PR template (#2161)
pano9000 Feb 8, 2023
cb91971
fix(isMobilePhone): fixed es-CU matching all numbers that start with …
klaframboise Mar 7, 2023
9e73a1c
feat(isMobilePhone): add locales Wallis and Futuna fr-WF (#2209)
aidos42 Mar 27, 2023
698f4e6
fix(isVAT): corrected validation for Swiss (CH) locale (#2203)
jimmyorpheus Mar 27, 2023
fc49ad7
new validator: isLocale, add support for validation of more valid lan…
kwahome Mar 27, 2023
9ba1735
new validator: isMailtoURI, validate the mailto link URI format (#2188)
uksarkar Mar 27, 2023
df1351a
fix(isDate): enhance Date declaration compatibility across multiple e…
CiprianS Jun 12, 2023
4f63909
feat(isAlpha, isAlphanumeric): add kazakh locale, kk-KZ (#2226)
BekStar7 Jun 12, 2023
63b1e4d
fix(isEmail) do not allow non-breaking space in user part (#2237)
jeremy21212121 Jun 26, 2023
3507d27
fix(isJWT): fix validation issue in isJWT function (#2217)
Prathamesh061 Jun 26, 2023
4c25f26
refactor(isCreditCard): create allCards dynamically (#2117)
pano9000 Jun 26, 2023
2440c39
feat(isIBAN): add Morocco (MA) IBAN format (#2025)
lroudge Jun 26, 2023
2ef9a83
feat(isMobilePhone): Added regex for Sudan ar-SD (#2246)
Hussienma Jul 24, 2023
f303d39
feat(isIBAN): add white and blacklist options to the isIBAN validator…
edilson Aug 3, 2023
ad41eba
feat(IsFQDN): Add a test that asserts numeric chars in tld are reject…
aalekhpatel07 Aug 3, 2023
2f551c6
fix(isMobilePhone): fixed pl-PL matching numbers that start with 45 (…
czerwony03 Aug 3, 2023
6be9634
feat(isEmail) extend to enable allow_underscores in domain (#2229)
guspower Aug 3, 2023
f074abd
13.11.0
profnandaa Aug 3, 2023
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
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ feat(validatorName): brief title of what has been done

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

<!--- provide some (credible) references showing the structure of the data to be validated, if applicable --->

## Checklist

- [ ] PR contains only changes related; no stray files, etc.
- [ ] README updated (where applicable)
- [ ] Tests written (where applicable)
- [ ] References provided in PR (where applicable)
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# 13.11.0

### New Features / Validators

- [#2144](https://github.com/validatorjs/validator.js/pull/2144) `isFreightContainerID`: for shipping containers IDs @songyuew
- [#2188](https://github.com/validatorjs/validator.js/pull/2188) `isMailtoURI` @uksarkar

### Fixes, New Locales and Enhancements

- [#2025](https://github.com/validatorjs/validator.js/pull/2025) `isIBAN` add `MA` locale @lroudge
- [#2117](https://github.com/validatorjs/validator.js/pull/2117) `isCreditCard` refactor @pano9000
- [#2189](https://github.com/validatorjs/validator.js/pull/2189) `isLocale` add support for more language tags @kwahome
- [#2203](https://github.com/validatorjs/validator.js/pull/2203) `isVAT` for `CU` @jimmyorpheus
- [#2217](https://github.com/validatorjs/validator.js/pull/2217) `isJWT` @Prathamesh061
- [#2222](https://github.com/validatorjs/validator.js/pull/2222) `IsFQDN` test enhancements @aalekhpatel07
- [#2226](https://github.com/validatorjs/validator.js/pull/2226) `isAlpha`, `isAlphanumeric` for `kk-KZ` @BekStar7
- [#2229](https://github.com/validatorjs/validator.js/pull/2229) `isEmail` support `allow_underscores` @guspower
- [#2231](https://github.com/validatorjs/validator.js/pull/2231) `isDate` enhance Date declaration compatibility across multiple environments @CiprianS
- [#2235](https://github.com/validatorjs/validator.js/pull/2235) `isIBAN` add white and blacklist options to the isIBAN validator @edilson
- [#2237](https://github.com/validatorjs/validator.js/pull/2237) `isEmail` do not allow non-breaking space in user part @jeremy21212121
- `isMobilePhone`:
- [#2175](https://github.com/validatorjs/validator.js/pull/2175) `so-SO` @ohersi
- [#2176](https://github.com/validatorjs/validator.js/pull/2176) `fr-CF` @cheboi
- [#2197](https://github.com/validatorjs/validator.js/pull/2197) `es-CU` @klaframboise
- [#2202](https://github.com/validatorjs/validator.js/pull/2202) `pl-PL` @czerwony03
- [#2209](https://github.com/validatorjs/validator.js/pull/2209) `fr-WF` @aidos42
- [#2246](https://github.com/validatorjs/validator.js/pull/2246) `ar-SD` @Hussienma



# 13.9.0

### New Features / Validators
Expand Down
16 changes: 10 additions & 6 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "validator",
"description": "String validation and sanitization",
"version": "13.9.0",
"version": "13.11.0",
"sideEffects": false,
"homepage": "https://github.com/validatorjs/validator.js",
"files": [
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import isCurrency from './lib/isCurrency';

import isBtcAddress from './lib/isBtcAddress';

import { isISO6346, isFreightContainerID } from './lib/isISO6346';
import isISO6391 from './lib/isISO6391';
import isISO8601 from './lib/isISO8601';
import isRFC3339 from './lib/isRFC3339';
Expand All @@ -100,6 +101,7 @@ import isBase58 from './lib/isBase58';
import isBase64 from './lib/isBase64';
import isDataURI from './lib/isDataURI';
import isMagnetURI from './lib/isMagnetURI';
import isMailtoURI from './lib/isMailtoURI';

import isMimeType from './lib/isMimeType';

Expand All @@ -124,7 +126,7 @@ import isStrongPassword from './lib/isStrongPassword';

import isVAT from './lib/isVAT';

const version = '13.9.0';
const version = '13.11.0';

const validator = {
version,
Expand Down Expand Up @@ -199,6 +201,8 @@ const validator = {
isEthereumAddress,
isCurrency,
isBtcAddress,
isISO6346,
isFreightContainerID,
isISO6391,
isISO8601,
isRFC3339,
Expand All @@ -210,6 +214,7 @@ const validator = {
isBase64,
isDataURI,
isMagnetURI,
isMailtoURI,
isMimeType,
isLatLong,
ltrim,
Expand Down
4 changes: 3 additions & 1 deletion src/lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const alpha = {
'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
'ru-RU': /^[А-ЯЁ]+$/i,
'kk-KZ': /^[А-ЯЁ\u04D8\u04B0\u0406\u04A2\u0492\u04AE\u049A\u04E8\u04BA]+$/i,
'sl-SI': /^[A-ZČĆĐŠŽ]+$/i,
'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i,
Expand Down Expand Up @@ -58,6 +59,7 @@ export const alphanumeric = {
'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
'ru-RU': /^[0-9А-ЯЁ]+$/i,
'kk-KZ': /^[0-9А-ЯЁ\u04D8\u04B0\u0406\u04A2\u0492\u04AE\u049A\u04E8\u04BA]+$/i,
'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
Expand Down Expand Up @@ -125,7 +127,7 @@ export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
export const commaDecimal = [
'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR',
'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT',
'ru-RU', 'si-LK', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN',
'ru-RU', 'kk-KZ', 'si-LK', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN',
];

for (let i = 0; i < dotDecimal.length; i++) {
Expand Down
16 changes: 12 additions & 4 deletions src/lib/isCreditCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ const cards = {
unionpay: /^(6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
visa: /^(?:4[0-9]{12})(?:[0-9]{3,6})?$/,
};
/* eslint-disable max-len */
const allCards = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
/* eslint-enable max-len */

const allCards = (() => {
const tmpCardsArray = [];
for (const cardProvider in cards) {
// istanbul ignore else
if (cards.hasOwnProperty(cardProvider)) {
tmpCardsArray.push(cards[cardProvider]);
}
}
return tmpCardsArray;
})();

export default function isCreditCard(card, options = {}) {
assertString(card);
Expand All @@ -26,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.test(sanitized))) {
} else if (!allCards.some(cardProvider => cardProvider.test(sanitized))) {
// no specific provider
return false;
}
Expand Down
20 changes: 19 additions & 1 deletion src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,25 @@ export default function isDate(input, options) {
dateObj[formatWord.charAt(0)] = dateWord;
}

return new Date(`${dateObj.m}/${dateObj.d}/${dateObj.y}`).getDate() === +dateObj.d;
let fullYear = dateObj.y;

if (dateObj.y.length === 2) {
const parsedYear = parseInt(dateObj.y, 10);

if (isNaN(parsedYear)) {
return false;
}

const currentYearLastTwoDigits = new Date().getFullYear() % 100;

if (parsedYear < currentYearLastTwoDigits) {
fullYear = `20${dateObj.y}`;
} else {
fullYear = `19${dateObj.y}`;
}
}

return new Date(`${fullYear}-${dateObj.m}-${dateObj.d}`).getDate() === +dateObj.d;
}

if (!options.strictMode) {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/isEmail.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import assertString from './util/assertString';

import merge from './util/merge';
import isByteLength from './isByteLength';
import isFQDN from './isFQDN';
import isIP from './isIP';
import merge from './util/merge';

const default_email_options = {
allow_display_name: false,
allow_underscores: false,
require_display_name: false,
allow_utf8_local_part: true,
require_tld: true,
Expand All @@ -22,7 +23,7 @@ const splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
const emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
const gmailUserPart = /^[a-z\d]+$/;
const quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
const emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
const emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A1-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
const quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
const defaultMaxEmailLength = 254;
/* eslint-enable max-len */
Expand Down Expand Up @@ -142,6 +143,7 @@ export default function isEmail(str, options) {
if (!isFQDN(domain, {
require_tld: options.require_tld,
ignore_max_length: options.ignore_max_length,
allow_underscores: options.allow_underscores,
})) {
if (!options.allow_ip_domain) {
return false;
Expand Down
51 changes: 47 additions & 4 deletions src/lib/isIBAN.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ibanRegexThroughCountryCode = {
LT: /^(LT[0-9]{2})\d{16}$/,
LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/,
LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/,
MA: /^(MA[0-9]{26})$/,
MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
MD: /^(MD[0-9]{2})[A-Z0-9]{20}$/,
ME: /^(ME[0-9]{2})\d{18}$/,
Expand Down Expand Up @@ -86,6 +87,25 @@ const ibanRegexThroughCountryCode = {
XK: /^(XK[0-9]{2})\d{16}$/,
};

/**
* Check if the country codes passed are valid using the
* ibanRegexThroughCountryCode as a reference
*
* @param {array} countryCodeArray
* @return {boolean}
*/

function hasOnlyValidCountryCodes(countryCodeArray) {
const countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray
.filter(countryCode => !(countryCode in ibanRegexThroughCountryCode));

if (countryCodeArrayFilteredWithObjectIbanCode.length > 0) {
return false;
}

return true;
}

/**
* Check whether string has correct universal IBAN format
* The IBAN consists of up to 34 alphanumeric characters, as follows:
Expand All @@ -95,14 +115,37 @@ const ibanRegexThroughCountryCode = {
* NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
*
* @param {string} str - string under validation
* @param {object} options - object to pass the countries to be either whitelisted or blacklisted
* @return {boolean}
*/
function hasValidIbanFormat(str) {
function hasValidIbanFormat(str, options) {
// Strip white spaces and hyphens
const strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
const isoCountryCode = strippedStr.slice(0, 2).toUpperCase();

return (isoCountryCode in ibanRegexThroughCountryCode) &&
const isoCountryCodeInIbanRegexCodeObject = isoCountryCode in ibanRegexThroughCountryCode;

if (options.whitelist) {
if (!hasOnlyValidCountryCodes(options.whitelist)) {
return false;
}

const isoCountryCodeInWhiteList = options.whitelist.includes(isoCountryCode);

if (!isoCountryCodeInWhiteList) {
return false;
}
}

if (options.blacklist) {
const isoCountryCodeInBlackList = options.blacklist.includes(isoCountryCode);

if (isoCountryCodeInBlackList) {
return false;
}
}

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

Expand Down Expand Up @@ -130,10 +173,10 @@ function hasValidIbanChecksum(str) {
return remainder === 1;
}

export default function isIBAN(str) {
export default function isIBAN(str, options = {}) {
assertString(str);

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

export const locales = Object.keys(ibanRegexThroughCountryCode);
37 changes: 37 additions & 0 deletions src/lib/isISO6346.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import assertString from './util/assertString';

// https://en.wikipedia.org/wiki/ISO_6346
// according to ISO6346 standard, checksum digit is mandatory for freight container but recommended
// for other container types (J and Z)
const isISO6346Str = /^[A-Z]{3}(U[0-9]{7})|([J,Z][0-9]{6,7})$/;
const isDigit = /^[0-9]$/;

export function isISO6346(str) {
assertString(str);

str = str.toUpperCase();

if (!isISO6346Str.test(str)) return false;

if (str.length === 11) {
let sum = 0;
for (let i = 0; i < str.length - 1; i++) {
if (!isDigit.test(str[i])) {
let convertedCode;
const letterCode = str.charCodeAt(i) - 55;
if (letterCode < 11) convertedCode = letterCode;
else if (letterCode >= 11 && letterCode <= 20) convertedCode = 12 + (letterCode % 11);
else if (letterCode >= 21 && letterCode <= 30) convertedCode = 23 + (letterCode % 21);
else convertedCode = 34 + (letterCode % 31);
sum += convertedCode * (2 ** i);
} else sum += str[i] * (2 ** i);
}

const checkSumDigit = sum % 11;
return Number(str[str.length - 1]) === checkSumDigit;
}

return true;
}

export const isFreightContainerID = isISO6346;
2 changes: 1 addition & 1 deletion src/lib/isJWT.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function isJWT(str) {
const dotSplit = str.split('.');
const len = dotSplit.length;

if (len > 3 || len < 2) {
if (len !== 3) {
return false;
}

Expand Down
Loading
Loading