Skip to content

Commit a417afc

Browse files
authored
Merge branch 'master' into issue_2039
2 parents 8476579 + c174a1f commit a417afc

20 files changed

+923
-310
lines changed

CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
1+
# 13.15.0
2+
3+
### New Features / Validators
4+
5+
- [#2399](https://github.com/validatorjs/validator.js/pull/2399) `isISO31661Numeric` @RobinvanderVliet
6+
- [#2294](https://github.com/validatorjs/validator.js/pull/2294) `isULID` @arafatkn
7+
- [#2215](https://github.com/validatorjs/validator.js/pull/2215) `isISO15924` @xDivisionByZerox
8+
9+
### Fixes, New Locales and Enhancements
10+
11+
- `isMobilePhone`
12+
- [#2395](https://github.com/validatorjs/validator.js/pull/2395) add `es-GT` locale @ignaciosuarezquilis
13+
- [#1971](https://github.com/validatorjs/validator.js/pull/1971) improve `en-GB` locale @ihmpavel
14+
- [#2359](https://github.com/validatorjs/validator.js/pull/2359) improve `uk-UA` locale @arttiger
15+
- [#2350](https://github.com/validatorjs/validator.js/pull/2350) improve `ky-KG` locale @sadraliev
16+
- [#2482](https://github.com/validatorjs/validator.js/pull/2482) improve `en-ZM` locale @sonikishan
17+
- [#2362](https://github.com/validatorjs/validator.js/pull/2362) improve `en-GH` locale @NanaAb-116
18+
- [#2500](https://github.com/validatorjs/validator.js/pull/2500) add `mk-MK` locale @eshward95
19+
- [#2534](https://github.com/validatorjs/validator.js/pull/2534) improve `sq-AL` locale @nichoola
20+
- [#2406](https://github.com/validatorjs/validator.js/pull/2406) `isBtcAddress` support all address formats and testnets @madoke
21+
- [#2339](https://github.com/validatorjs/validator.js/pull/2339) `isIBAN` improve `VG` regex @ST-DDT
22+
- [#2332](https://github.com/validatorjs/validator.js/pull/2332) `isISO4217` update currency codes @cbodtorf
23+
- [#2291](https://github.com/validatorjs/validator.js/pull/2291) `isIdentityCard` add `PK` locale @Daniyal-Qureshi
24+
- [#2414](https://github.com/validatorjs/validator.js/pull/2414) `isEmail` fix blacklist_chars @keshavlingala
25+
- [#2416](https://github.com/validatorjs/validator.js/pull/2416) `isInt`/`isFloat` handle undefined and null values @Daniyal-Qureshi
26+
- [#2415](https://github.com/validatorjs/validator.js/pull/2415) `isPostalCode` add `CO` locale @jorgevrgs
27+
- [#2404](https://github.com/validatorjs/validator.js/pull/2404) `isPassportNumber` export `passportNumberLocales` @derekparnell
28+
- [#2029](https://github.com/validatorjs/validator.js/pull/2029) `isRgbColor` add `allowSpaces` option @a-h-i
29+
- [#2421](https://github.com/validatorjs/validator.js/pull/2421) `isUUID` require valid variant field and require RFC9562 UUID in version `all` @broofa
30+
- [#2439](https://github.com/validatorjs/validator.js/pull/2439) `isURL` add `max_allowed_length` option @pinkiesky
31+
- [#2437](https://github.com/validatorjs/validator.js/pull/2437) `isEmail` reject starting with double quotes @code0emperor
32+
- [#2333](https://github.com/validatorjs/validator.js/pull/2333) `isLicensePlate` add `en-SG` locale @Sabarinathan07
33+
- [#2441](https://github.com/validatorjs/validator.js/pull/2441) `normalizeEmail` add `yandex_convert_yandexru` option @AayushGH
34+
- [#2443](https://github.com/validatorjs/validator.js/pull/2443) `isDate` return false instead of Error in certain cases @pano9000
35+
- [#2474](https://github.com/validatorjs/validator.js/pull/2474) `isLength` add `discreteLengths` option @Suven-p
36+
- [#2481](https://github.com/validatorjs/validator.js/pull/2481) `isDate` disallow mismatching length in `strictMode` @sonikishan
37+
- [#2492](https://github.com/validatorjs/validator.js/pull/2492) `isISO6346` set check digit to 0 if remainder is 10 @joelcuy
38+
- [#2493](https://github.com/validatorjs/validator.js/pull/2493) `isPostalCode` improve `BR` locale @ticmaisdev
39+
- [#2494](https://github.com/validatorjs/validator.js/pull/2494) `isEmail` allow regexp in `host_whitelist` and `host_blacklist` @weikangchia
40+
- [#2518](https://github.com/validatorjs/validator.js/pull/2518) `isIBAN` improve `IE`/`PS` regex @Tarasz57
41+
- **Doc fixes and others:**
42+
- [#2402](https://github.com/validatorjs/validator.js/pull/2402) @BibhushanKarki
43+
- [#2394](https://github.com/validatorjs/validator.js/pull/2394) @RobinvanderVliet
44+
- [#1732](https://github.com/validatorjs/validator.js/pull/1732) @alguerocode
45+
- [#2413](https://github.com/validatorjs/validator.js/pull/2413) @rubiin
46+
- [#2408](https://github.com/validatorjs/validator.js/pull/2408) @profnandaa
47+
- [#2411](https://github.com/validatorjs/validator.js/pull/2411) @rubiin
48+
- [#2325](https://github.com/validatorjs/validator.js/pull/2325) @ovarn
49+
- [#2418](https://github.com/validatorjs/validator.js/pull/2418) @ihmpavel
50+
- [#2323](https://github.com/validatorjs/validator.js/pull/2323) @ovarn
51+
- [#2423](https://github.com/validatorjs/validator.js/pull/2423) @rubiin
52+
- [#2409](https://github.com/validatorjs/validator.js/pull/2409) @profnandaa
53+
- [#2442](https://github.com/validatorjs/validator.js/pull/2442) @pano9000
54+
155
# 13.12.0
256

357
### New Features / Validators

README.md

Lines changed: 7 additions & 5 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "validator",
33
"description": "String validation and sanitization",
4-
"version": "13.12.0",
4+
"version": "13.15.0",
55
"sideEffects": false,
66
"homepage": "https://github.com/validatorjs/validator.js",
77
"files": [

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { isISO6346, isFreightContainerID } from './lib/isISO6346';
9494
import isISO6391 from './lib/isISO6391';
9595
import isISO8601 from './lib/isISO8601';
9696
import isRFC3339 from './lib/isRFC3339';
97+
import isISO15924 from './lib/isISO15924';
9798
import isISO31661Alpha2 from './lib/isISO31661Alpha2';
9899
import isISO31661Alpha3 from './lib/isISO31661Alpha3';
99100
import isISO31661Numeric from './lib/isISO31661Numeric';
@@ -129,7 +130,7 @@ import isStrongPassword from './lib/isStrongPassword';
129130

130131
import isVAT from './lib/isVAT';
131132

132-
const version = '13.12.0';
133+
const version = '13.15.0';
133134

134135
const validator = {
135136
version,
@@ -211,6 +212,7 @@ const validator = {
211212
isFreightContainerID,
212213
isISO6391,
213214
isISO8601,
215+
isISO15924,
214216
isRFC3339,
215217
isISO31661Alpha2,
216218
isISO31661Alpha3,

src/lib/isBase64.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
import assertString from './util/assertString';
22
import merge from './util/merge';
33

4-
const notBase64 = /[^A-Z0-9+\/=]/i;
5-
const urlSafeBase64 = /^[A-Z0-9_\-]*$/i;
6-
7-
const defaultBase64Options = {
8-
urlSafe: false,
9-
};
4+
const base64WithPadding = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/;
5+
const base64WithoutPadding = /^[A-Za-z0-9+/]+$/;
6+
const base64UrlWithPadding = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}==|[A-Za-z0-9_-]{3}=|[A-Za-z0-9_-]{4})$/;
7+
const base64UrlWithoutPadding = /^[A-Za-z0-9_-]+$/;
108

119
export default function isBase64(str, options) {
1210
assertString(str);
13-
options = merge(options, defaultBase64Options);
14-
const len = str.length;
11+
options = merge(options, { urlSafe: false, padding: !options?.urlSafe });
1512

16-
if (options.urlSafe) {
17-
return urlSafeBase64.test(str);
18-
}
13+
if (str === '') return true;
1914

20-
if (len % 4 !== 0 || notBase64.test(str)) {
21-
return false;
15+
let regex;
16+
if (options.urlSafe) {
17+
regex = options.padding ? base64UrlWithPadding : base64UrlWithoutPadding;
18+
} else {
19+
regex = options.padding ? base64WithPadding : base64WithoutPadding;
2220
}
2321

24-
const firstPaddingChar = str.indexOf('=');
25-
return firstPaddingChar === -1 ||
26-
firstPaddingChar === len - 1 ||
27-
(firstPaddingChar === len - 2 && str[len - 1] === '=');
22+
return (!options.padding || str.length % 4 === 0) && regex.test(str);
2823
}

src/lib/isDate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function isDate(input, options) {
2828
options = merge(options, default_date_options);
2929
}
3030
if (typeof input === 'string' && isValidFormat(options.format)) {
31+
if (options.strictMode && input.length !== options.format.length) return false;
3132
const formatDelimiter = options.delimiters
3233
.find(delimiter => options.format.indexOf(delimiter) !== -1);
3334
const dateDelimiter = options.strictMode

src/lib/isEmail.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assertString from './util/assertString';
2+
import checkHost from './util/checkHost';
23

34
import isByteLength from './isByteLength';
45
import isFQDN from './isFQDN';
@@ -60,7 +61,6 @@ function validateDisplayName(display_name) {
6061
return true;
6162
}
6263

63-
6464
export default function isEmail(str, options) {
6565
assertString(str);
6666
options = merge(options, default_email_options);
@@ -97,11 +97,11 @@ export default function isEmail(str, options) {
9797
const domain = parts.pop();
9898
const lower_domain = domain.toLowerCase();
9999

100-
if (options.host_blacklist.includes(lower_domain)) {
100+
if (options.host_blacklist.length > 0 && checkHost(lower_domain, options.host_blacklist)) {
101101
return false;
102102
}
103103

104-
if (options.host_whitelist.length > 0 && !options.host_whitelist.includes(lower_domain)) {
104+
if (options.host_whitelist.length > 0 && !checkHost(lower_domain, options.host_whitelist)) {
105105
return false;
106106
}
107107

src/lib/isIBAN.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const ibanRegexThroughCountryCode = {
3939
GT: /^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,
4040
HR: /^(HR[0-9]{2})\d{17}$/,
4141
HU: /^(HU[0-9]{2})\d{24}$/,
42-
IE: /^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,
42+
IE: /^(IE[0-9]{2})[A-Z]{4}\d{14}$/,
4343
IL: /^(IL[0-9]{2})\d{19}$/,
4444
IQ: /^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,
4545
IR: /^(IR[0-9]{2})0\d{2}0\d{18}$/,
@@ -67,7 +67,7 @@ const ibanRegexThroughCountryCode = {
6767
NO: /^(NO[0-9]{2})\d{11}$/,
6868
PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,
6969
PL: /^(PL[0-9]{2})\d{24}$/,
70-
PS: /^(PS[0-9]{2})[A-Z0-9]{4}\d{21}$/,
70+
PS: /^(PS[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
7171
PT: /^(PT[0-9]{2})\d{21}$/,
7272
QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
7373
RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/,

src/lib/isIP.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,24 @@ const IPv6AddressRegExp = new RegExp('^(' +
4444
`(?::((?::${IPv6SegmentFormat}){0,5}:${IPv4AddressFormat}|(?::${IPv6SegmentFormat}){1,7}|:))` +
4545
')(%[0-9a-zA-Z.]{1,})?$');
4646

47-
export default function isIP(str, version = '') {
48-
assertString(str);
49-
version = String(version);
47+
export default function isIP(ipAddress, options = {}) {
48+
assertString(ipAddress);
49+
50+
// accessing 'arguments' for backwards compatibility: isIP(ipAddress [, version])
51+
// eslint-disable-next-line prefer-rest-params
52+
const version = (typeof options === 'object' ? options.version : arguments[1]) || '';
53+
5054
if (!version) {
51-
return isIP(str, 4) || isIP(str, 6);
55+
return isIP(ipAddress, { version: 4 }) || isIP(ipAddress, { version: 6 });
5256
}
53-
if (version === '4') {
54-
return IPv4AddressRegExp.test(str);
57+
58+
if (version.toString() === '4') {
59+
return IPv4AddressRegExp.test(ipAddress);
5560
}
56-
if (version === '6') {
57-
return IPv6AddressRegExp.test(str);
61+
62+
if (version.toString() === '6') {
63+
return IPv6AddressRegExp.test(ipAddress);
5864
}
65+
5966
return false;
6067
}

src/lib/isISO15924.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import assertString from './util/assertString';
2+
3+
// from https://www.unicode.org/iso15924/iso15924-codes.html
4+
const validISO15924Codes = new Set([
5+
'Adlm', 'Afak', 'Aghb', 'Ahom', 'Arab', 'Aran', 'Armi', 'Armn', 'Avst',
6+
'Bali', 'Bamu', 'Bass', 'Batk', 'Beng', 'Bhks', 'Blis', 'Bopo', 'Brah', 'Brai', 'Bugi', 'Buhd',
7+
'Cakm', 'Cans', 'Cari', 'Cham', 'Cher', 'Chis', 'Chrs', 'Cirt', 'Copt', 'Cpmn', 'Cprt', 'Cyrl', 'Cyrs',
8+
'Deva', 'Diak', 'Dogr', 'Dsrt', 'Dupl',
9+
'Egyd', 'Egyh', 'Egyp', 'Elba', 'Elym', 'Ethi',
10+
'Gara', 'Geok', 'Geor', 'Glag', 'Gong', 'Gonm', 'Goth', 'Gran', 'Grek', 'Gujr', 'Gukh', 'Guru',
11+
'Hanb', 'Hang', 'Hani', 'Hano', 'Hans', 'Hant', 'Hatr', 'Hebr', 'Hira', 'Hluw', 'Hmng', 'Hmnp', 'Hrkt', 'Hung',
12+
'Inds', 'Ital',
13+
'Jamo', 'Java', 'Jpan', 'Jurc',
14+
'Kali', 'Kana', 'Kawi', 'Khar', 'Khmr', 'Khoj', 'Kitl', 'Kits', 'Knda', 'Kore', 'Kpel', 'Krai', 'Kthi',
15+
'Lana', 'Laoo', 'Latf', 'Latg', 'Latn', 'Leke', 'Lepc', 'Limb', 'Lina', 'Linb', 'Lisu', 'Loma', 'Lyci', 'Lydi',
16+
'Mahj', 'Maka', 'Mand', 'Mani', 'Marc', 'Maya', 'Medf', 'Mend', 'Merc', 'Mero', 'Mlym', 'Modi', 'Mong', 'Moon', 'Mroo', 'Mtei', 'Mult', 'Mymr',
17+
'Nagm', 'Nand', 'Narb', 'Nbat', 'Newa', 'Nkdb', 'Nkgb', 'Nkoo', 'Nshu',
18+
'Ogam', 'Olck', 'Onao', 'Orkh', 'Orya', 'Osge', 'Osma', 'Ougr',
19+
'Palm', 'Pauc', 'Pcun', 'Pelm', 'Perm', 'Phag', 'Phli', 'Phlp', 'Phlv', 'Phnx', 'Plrd', 'Piqd', 'Prti', 'Psin',
20+
'Qaaa', 'Qaab', 'Qaac', 'Qaad', 'Qaae', 'Qaaf', 'Qaag', 'Qaah', 'Qaai', 'Qaaj', 'Qaak', 'Qaal', 'Qaam', 'Qaan', 'Qaao', 'Qaap', 'Qaaq', 'Qaar', 'Qaas', 'Qaat', 'Qaau', 'Qaav', 'Qaaw', 'Qaax', 'Qaay', 'Qaaz', 'Qaba', 'Qabb', 'Qabc', 'Qabd', 'Qabe', 'Qabf', 'Qabg', 'Qabh', 'Qabi', 'Qabj', 'Qabk', 'Qabl', 'Qabm', 'Qabn', 'Qabo', 'Qabp', 'Qabq', 'Qabr', 'Qabs', 'Qabt', 'Qabu', 'Qabv', 'Qabw', 'Qabx',
21+
'Ranj', 'Rjng', 'Rohg', 'Roro', 'Runr',
22+
'Samr', 'Sara', 'Sarb', 'Saur', 'Sgnw', 'Shaw', 'Shrd', 'Shui', 'Sidd', 'Sidt', 'Sind', 'Sinh', 'Sogd', 'Sogo', 'Sora', 'Soyo', 'Sund', 'Sunu', 'Sylo', 'Syrc', 'Syre', 'Syrj', 'Syrn',
23+
'Tagb', 'Takr', 'Tale', 'Talu', 'Taml', 'Tang', 'Tavt', 'Tayo', 'Telu', 'Teng', 'Tfng', 'Tglg', 'Thaa', 'Thai', 'Tibt', 'Tirh', 'Tnsa', 'Todr', 'Tols', 'Toto', 'Tutg',
24+
'Ugar',
25+
'Vaii', 'Visp', 'Vith',
26+
'Wara', 'Wcho', 'Wole',
27+
'Xpeo', 'Xsux',
28+
'Yezi', 'Yiii',
29+
'Zanb', 'Zinh', 'Zmth', 'Zsye', 'Zsym', 'Zxxx', 'Zyyy', 'Zzzz',
30+
]);
31+
32+
export default function isISO15924(str) {
33+
assertString(str);
34+
return validISO15924Codes.has(str);
35+
}
36+
37+
export const ScriptCodes = validISO15924Codes;

0 commit comments

Comments
 (0)