Repository: validatorjs/validator.js
Pull request #1697 (2021-07-16 07:41:36)

fix: npm installation error
Updated rollup to solve installation error

## Checklist

- [x] PR contains only changes related; no stray files, etc.
- [] README updated (where applicable)
- [] Tests written (where applicable)


codecov[bot]: # [Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1697?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs) Report
> Merging [#1697](https://codecov.io/gh/validatorjs/validator.js/pull/1697?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs) (49bc8fa) into [master](https://codecov.io/gh/validatorjs/validator.js/commit/b82d4e1b1f9dafcc130ca5dd548324a501741369?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs) (b82d4e1) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/validatorjs/validator.js/pull/1697/graphs/tree.svg?width=650&height=150&src=pr&token=YzR3kbN1m2&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs)](https://codecov.io/gh/validatorjs/validator.js/pull/1697?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs)

```diff
@@            Coverage Diff            @@
##            master     #1697   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          101       101           
  Lines         1855      1855           
=========================================
  Hits          1855      1855           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1697?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/validatorjs/validator.js/pull/1697?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs). Last update [b82d4e1...49bc8fa](https://codecov.io/gh/validatorjs/validator.js/pull/1697?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=validatorjs).

rubiin: rollup latest version doesnot seem to support older versions. Also node 6.0 is way old i think we should drop tests for it as its likely someone is using that
fedeci: Even if node 6 may not be used anymore this is a breaking change and should be released in a new major.
rubiin: > Even if node 6 may not be used anymore this is a breaking change and should be released in a new major.

however its a blocker if you cant install the package dependencies after forking. @profnandaa 
rubiin: tested on node v10,12 and v14.
profnandaa: Don't leave out Node 6 yet, there's a time it helped us catch an old browser incompatibility, see #1357 

Patch:
diff --git a/README.md b/README.md
index 67496d8..e5cf048 100644
--- a/README.md
+++ b/README.md
@@ -93,7 +93,7 @@ Validator                               | Description
 **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)
 **isBefore(str [, date])**              | check if the string is a date that's before the specified date.
 **isBIC(str)**                          | check if a string is a BIC (Bank Identification Code) or SWIFT code.
-**isBoolean(str)**                      | check if a string is a boolean.
+**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']).
 **isBtcAddress(str)**            | check if the string is a valid BTC address.
 **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}`.
 **isCreditCard(str)**                   | check if the string is a credit card.
@@ -132,7 +132,7 @@ Validator                               | Description
 **isJWT(str)**                         | check if the string is valid JWT token.
 **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.
 **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.
-**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`).
+**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`)
 **isLocale(str)**                       | check if the string is a locale
 **isLowercase(str)**                    | check if the string is lowercase.
 **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'.
diff --git a/build-browser.js b/build-browser.js
index 6101d65..c863bd3 100644
--- a/build-browser.js
+++ b/build-browser.js
@@ -1,34 +1,32 @@
 /* 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';
+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',
+  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);
-});
+})
+  .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 72573e3..2392153 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,7 @@
     "mocha": "^6.2.3",
     "nyc": "^14.1.0",
     "rimraf": "^3.0.0",
-    "rollup": "^0.43.0",
+    "rollup": "^0.47.0",
     "rollup-plugin-babel": "^4.0.1",
     "uglify-js": "^3.0.19"
   },
@@ -72,4 +72,4 @@
     "node": ">= 0.10"
   },
   "license": "MIT"
-}
+}
\ No newline at end of file
diff --git a/src/lib/isBoolean.js b/src/lib/isBoolean.js
index e7cb27d..9fddc2b 100644
--- a/src/lib/isBoolean.js
+++ b/src/lib/isBoolean.js
@@ -1,6 +1,15 @@
 import assertString from './util/assertString';
 
-export default function isBoolean(str) {
+const defaultOptions = { loose: false };
+const strictBooleans = ['true', 'false', '1', '0'];
+const looseBooleans = [...strictBooleans, 'yes', 'no'];
+
+export default function isBoolean(str, options = defaultOptions) {
   assertString(str);
-  return (['true', 'false', '1', '0'].indexOf(str) >= 0);
+
+  if (options.loose) {
+    return looseBooleans.includes(str.toLowerCase());
+  }
+
+  return strictBooleans.includes(str);
 }
diff --git a/src/lib/isLicensePlate.js b/src/lib/isLicensePlate.js
index a28d66d..d81995b 100644
--- a/src/lib/isLicensePlate.js
+++ b/src/lib/isLicensePlate.js
@@ -1,6 +1,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H|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),
   'de-LI': str => /^FL[- ]?\d{1,5}[UZ]?$/.test(str),
diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js
index 6bf6d22..b2839d6 100644
--- a/src/lib/isMobilePhone.js
+++ b/src/lib/isMobilePhone.js
@@ -25,7 +25,7 @@ const phones = {
   'ca-AD': /^(\+376)?[346]\d{5}$/,
   'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
   'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
-  'de-DE': /^(\+49)?0?[1|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
+  '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}$/,
   'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
   'de-CH': /^(\+41|0)([1-9])\d{1,9}$/,
   'de-LU': /^(\+352)?((6\d1)\d{6})$/,


Test patch:
diff --git a/test/validators.js b/test/validators.js
index 57f2d2b..ef24ea4 100644
--- a/test/validators.js
+++ b/test/validators.js
@@ -5828,21 +5828,20 @@ describe('Validators', () => {
       {
         locale: 'de-DE',
         valid: [
-          '+49015123456789',
           '+4915123456789',
           '+4930405044550',
           '015123456789',
-          '15123456789',
-          '15623456789',
-          '15623456789',
-          '1601234567',
-          '16012345678',
-          '1621234567',
-          '1631234567',
-          '1701234567',
-          '17612345678',
-          '15345678910',
-          '15412345678',
+          '015123456789',
+          '015623456789',
+          '015623456789',
+          '01601234567',
+          '016012345678',
+          '01621234567',
+          '01631234567',
+          '01701234567',
+          '017612345678',
+          '015345678910',
+          '015412345678',
         ],
         invalid: [
           '34412345678',
@@ -5852,6 +5851,7 @@ describe('Validators', () => {
           '16412345678',
           '17012345678',
           '+4912345678910',
+          '+49015123456789',
         ],
       },
       {
@@ -8873,6 +8873,37 @@ describe('Validators', () => {
     });
   });
 
+  it('should validate booleans with option loose set to true', () => {
+    test({
+      validator: 'isBoolean',
+      args: [
+        { loose: true },
+      ],
+      valid: [
+        'true',
+        'True',
+        'TRUE',
+        'false',
+        'False',
+        'FALSE',
+        '0',
+        '1',
+        'yes',
+        'Yes',
+        'YES',
+        'no',
+        'No',
+        'NO',
+      ],
+      invalid: [
+        '1.0',
+        '0.0',
+        'true ',
+        ' false',
+      ],
+    });
+  });
+
   const validISO8601 = [
     '2009-12T12:34',
     '2009',
@@ -10696,6 +10727,31 @@ describe('Validators', () => {
         'AAA 00 AAA',
       ],
     });
+    test({
+      validator: 'isLicensePlate',
+      args: ['cs-CZ'],
+      valid: [
+        'ALA4011',
+        '4A23000',
+        'DICTAT0R',
+        'VETERAN',
+        'AZKVIZ8',
+        '2A45876',
+        'DIC-TAT0R',
+      ],
+      invalid: [
+        '',
+        'invalidlicenseplate',
+        'LN5758898',
+        'X-|$|-X',
+        'AE0F-OP4',
+        'GO0MER',
+        '2AAAAAAAA',
+        'FS AB 1234 E',
+        'GB999 9999 00',
+      ],
+    });
+
     test({
       validator: 'isLicensePlate',
       args: ['pt-BR'],