Skip to content

Commit c0f9b3c

Browse files
authored
Merge branch 'master' into master
2 parents c02a0f7 + 01eeaef commit c0f9b3c

File tree

8 files changed

+98
-19
lines changed

8 files changed

+98
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Validator | Description
9393
**isBase64(str [, options])** | check if a string is base64 encoded. options is optional and defaults to `{urlSafe: false}`<br/> when `urlSafe` is true it tests the given base64 encoded string is [url safe](https://base64.guru/standards/base64url)
9494
**isBefore(str [, date])** | check if the string is a date that's before the specified date.
9595
**isBIC(str)** | check if a string is a BIC (Bank Identification Code) or SWIFT code.
96-
**isBoolean(str)** | check if a string is a boolean.
96+
**isBoolean(str [, options])** | check if a string is a boolean.<br/>`options` is an object which defaults to `{ loose: false }`. If loose is is set to false, the validator will strictly match ['true', 'false', '0', '1']. If loose is set to true, the validator will also match 'yes', 'no', and will match a valid boolean string of any case. (eg: ['true', 'True', 'TRUE']).
9797
**isBtcAddress(str)** | check if the string is a valid BTC address.
9898
**isByteLength(str [, options])** | check if the string's length (in UTF-8 bytes) falls in a range.<br/><br/>`options` is an object which defaults to `{min:0, max: undefined}`.
9999
**isCreditCard(str)** | check if the string is a credit card.
@@ -132,7 +132,7 @@ Validator | Description
132132
**isJWT(str)** | check if the string is valid JWT token.
133133
**isLatLong(str [, options])** | check if the string is a valid latitude-longitude coordinate in the format `lat,long` or `lat, long`.<br/><br/>`options` is an object that defaults to `{ checkDMS: false }`. Pass `checkDMS` as `true` to validate DMS(degrees, minutes, and seconds) latitude-longitude format.
134134
**isLength(str [, options])** | check if the string's length falls in a range.<br/><br/>`options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs.
135-
**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.<br/><br/>(locale is one of `['de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR'']` or `any`).
135+
**isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.<br/><br/>(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'pt-PT', 'sq-AL', 'pt-BR']` or `any`)
136136
**isLocale(str)** | check if the string is a locale
137137
**isLowercase(str)** | check if the string is lowercase.
138138
**isMACAddress(str)** | check if the string is a MAC address.<br/><br/>`options` is an object which defaults to `{no_separators: false}`. If `no_separators` is true, the validator will allow MAC addresses without separators. Also, it allows the use of hyphens, spaces or dots e.g '01 02 03 04 05 ab', '01-02-03-04-05-ab' or '0102.0304.05ab'.

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import isHSL from './lib/isHSL';
4848

4949
import isISRC from './lib/isISRC';
5050

51-
import isIBAN from './lib/isIBAN';
51+
import isIBAN, { locales as ibanLocales } from './lib/isIBAN';
5252
import isBIC from './lib/isBIC';
5353

5454
import isMD5 from './lib/isMD5';
@@ -222,6 +222,7 @@ const validator = {
222222
isDate,
223223
isLicensePlate,
224224
isVAT,
225+
ibanLocales,
225226
};
226227

227228
export default validator;

src/lib/isBoolean.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import assertString from './util/assertString';
22

3-
export default function isBoolean(str) {
3+
const defaultOptions = { loose: false };
4+
const strictBooleans = ['true', 'false', '1', '0'];
5+
const looseBooleans = [...strictBooleans, 'yes', 'no'];
6+
7+
export default function isBoolean(str, options = defaultOptions) {
48
assertString(str);
5-
return (['true', 'false', '1', '0'].indexOf(str) >= 0);
9+
10+
if (options.loose) {
11+
return looseBooleans.includes(str.toLowerCase());
12+
}
13+
14+
return strictBooleans.includes(str);
615
}

src/lib/isIBAN.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,5 @@ export default function isIBAN(str) {
135135

136136
return hasValidIbanFormat(str) && hasValidIbanChecksum(str);
137137
}
138+
139+
export const locales = Object.keys(ibanRegexThroughCountryCode);

src/lib/isLicensePlate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import assertString from './util/assertString';
22

33
const validators = {
4+
'cs-CZ': str =>
5+
/^(([ABCDEFHKIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str),
46
'de-DE': str =>
57
/^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS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ED|FLÖ|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str),
68
'de-LI': str => /^FL[- ]?\d{1,5}[UZ]?$/.test(str),

src/lib/isMobilePhone.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const phones = {
2525
'ca-AD': /^(\+376)?[346]\d{5}$/,
2626
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
2727
'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
28-
'de-DE': /^(\+49)?0?[1|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
28+
'de-DE': /^((\+49|0)[1|3])([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7,9}$/,
2929
'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
3030
'de-CH': /^(\+41|0)([1-9])\d{1,9}$/,
3131
'de-LU': /^(\+352)?((6\d1)\d{6})$/,
@@ -114,7 +114,7 @@ const phones = {
114114
'uk-UA': /^(\+?38|8)?0\d{9}$/,
115115
'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
116116
'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/,
117-
'zh-CN': /^((\+|00)86)?1([3456789][0-9]|4[579]|6[67]|7[01235678]|9[012356789])[0-9]{8}$/,
117+
'zh-CN': /^((\+|00)86)?1([3456789][0-9]|4[579]|6[2567]|7[01235678]|9[012356789])[0-9]{8}$/,
118118
'zh-TW': /^(\+?886\-?|0)?9\d{8}$/,
119119
};
120120
/* eslint-enable max-len */

test/exports.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { locales as isAlphaLocales } from '../src/lib/isAlpha';
55
import { locales as isAlphanumericLocales } from '../src/lib/isAlphanumeric';
66
import { locales as isMobilePhoneLocales } from '../src/lib/isMobilePhone';
77
import { locales as isFloatLocales } from '../src/lib/isFloat';
8+
import { locales as ibanCountryCodes } from '../src/lib/isIBAN';
89

910
describe('Exports', () => {
1011
it('should export validators', () => {
@@ -50,4 +51,9 @@ describe('Exports', () => {
5051
assert.ok(isFloatLocales instanceof Array);
5152
assert.ok(validator.isFloatLocales instanceof Array);
5253
});
54+
55+
it('should export a list of country codes that implement IBAN', () => {
56+
assert.ok(ibanCountryCodes instanceof Array);
57+
assert.ok(validator.ibanLocales instanceof Array);
58+
});
5359
});

test/validators.js

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5828,21 +5828,20 @@ describe('Validators', () => {
58285828
{
58295829
locale: 'de-DE',
58305830
valid: [
5831-
'+49015123456789',
58325831
'+4915123456789',
58335832
'+4930405044550',
58345833
'015123456789',
5835-
'15123456789',
5836-
'15623456789',
5837-
'15623456789',
5838-
'1601234567',
5839-
'16012345678',
5840-
'1621234567',
5841-
'1631234567',
5842-
'1701234567',
5843-
'17612345678',
5844-
'15345678910',
5845-
'15412345678',
5834+
'015123456789',
5835+
'015623456789',
5836+
'015623456789',
5837+
'01601234567',
5838+
'016012345678',
5839+
'01621234567',
5840+
'01631234567',
5841+
'01701234567',
5842+
'017612345678',
5843+
'015345678910',
5844+
'015412345678',
58465845
],
58475846
invalid: [
58485847
'34412345678',
@@ -5852,6 +5851,7 @@ describe('Validators', () => {
58525851
'16412345678',
58535852
'17012345678',
58545853
'+4912345678910',
5854+
'+49015123456789',
58555855
],
58565856
},
58575857
{
@@ -5987,6 +5987,9 @@ describe('Validators', () => {
59875987
'16565600001',
59885988
'+8617269427292',
59895989
'008617269427292',
5990+
'16238234822',
5991+
'008616238234822',
5992+
'+8616238234822',
59905993
],
59915994
invalid: [
59925995
'12345',
@@ -8874,6 +8877,37 @@ describe('Validators', () => {
88748877
});
88758878
});
88768879

8880+
it('should validate booleans with option loose set to true', () => {
8881+
test({
8882+
validator: 'isBoolean',
8883+
args: [
8884+
{ loose: true },
8885+
],
8886+
valid: [
8887+
'true',
8888+
'True',
8889+
'TRUE',
8890+
'false',
8891+
'False',
8892+
'FALSE',
8893+
'0',
8894+
'1',
8895+
'yes',
8896+
'Yes',
8897+
'YES',
8898+
'no',
8899+
'No',
8900+
'NO',
8901+
],
8902+
invalid: [
8903+
'1.0',
8904+
'0.0',
8905+
'true ',
8906+
' false',
8907+
],
8908+
});
8909+
});
8910+
88778911
const validISO8601 = [
88788912
'2009-12T12:34',
88798913
'2009',
@@ -10697,6 +10731,31 @@ describe('Validators', () => {
1069710731
'AAA 00 AAA',
1069810732
],
1069910733
});
10734+
test({
10735+
validator: 'isLicensePlate',
10736+
args: ['cs-CZ'],
10737+
valid: [
10738+
'ALA4011',
10739+
'4A23000',
10740+
'DICTAT0R',
10741+
'VETERAN',
10742+
'AZKVIZ8',
10743+
'2A45876',
10744+
'DIC-TAT0R',
10745+
],
10746+
invalid: [
10747+
'',
10748+
'invalidlicenseplate',
10749+
'LN5758898',
10750+
'X-|$|-X',
10751+
'AE0F-OP4',
10752+
'GO0MER',
10753+
'2AAAAAAAA',
10754+
'FS AB 1234 E',
10755+
'GB999 9999 00',
10756+
],
10757+
});
10758+
1070010759
test({
1070110760
validator: 'isLicensePlate',
1070210761
args: ['pt-BR'],

0 commit comments

Comments
 (0)