From ae711d6c6d1da5f2f90107b5f9f2b0e7710eb753 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 00:05:03 +0530 Subject: [PATCH 01/40] Added Exact Condition for String Length & Updated README.md --- README.md | 2 +- src/lib/isLength.js | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 961b50d9a..1ed947944 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Validator | Description **isJSON(str [, options])** | check if the string is valid JSON (note: uses JSON.parse).

`options` is an object which defaults to `{ allow_primitives: false }`. If `allow_primitives` is true, the primitives 'true', 'false' and 'null' are accepted as valid JSON values. **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`.

`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.

`options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs. +**isLength(str [, options])** | check if the string's length falls in a range and equal to exactValue if provided.

`options` is an object which defaults to `{min:0, max: undefined, exact: undefined}`. Note: this function takes into account surrogate pairs. **isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'fi-FI', 'pt-BR', 'pt-PT', 'sq-AL', 'sv-SE', 'en-IN', 'hi-IN', 'gu-IN', 'as-IN', 'bn-IN', 'kn-IN', 'ml-IN', 'mr-IN', 'or-IN', 'pa-IN', 'sa-IN', 'ta-IN', 'te-IN', 'kok-IN']` or `any`) **isLocale(str)** | check if the string is a locale **isLowercase(str)** | check if the string is lowercase. diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 4ef8b83eb..46a695a66 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -1,19 +1,45 @@ -import assertString from './util/assertString'; +import assertString from './util/assertString.js'; /* eslint-disable prefer-rest-params */ export default function isLength(str, options) { assertString(str); let min; let max; + let exact; + let result; + let isPerfect = false; if (typeof (options) === 'object') { min = options.min || 0; max = options.max; + exact = options.exact; } else { // backwards compatibility: isLength(str, min [, max]) min = arguments[1] || 0; max = arguments[2]; + exact = arguments[3]; } const presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || []; const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; const len = str.length - presentationSequences.length - surrogatePairs.length; - return len >= min && (typeof max === 'undefined' || len <= max); + result = len >= min && (typeof max === 'undefined' || len <= max); + if (result === false || typeof exact === 'undefined') return result; + if (Array.isArray(exact) === true) { + for (let oneElem of exact) { + if (len === oneElem) { + isPerfect = true; + break; + } + } + } else if (typeof exact === 'number') { + if (len === exact) { + isPerfect = true; + } + } else if (typeof exact === 'object') { + for (let key in exact) { + if (len === exact[key]) { + isPerfect = true; + break; + } + } + } + return isPerfect; } From f93cf70eee496ec42aa051e3a75e6094c62eec10 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 00:23:14 +0530 Subject: [PATCH 02/40] Fixed Small Issue --- src/lib/isLength.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 46a695a66..6ac020a44 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -1,4 +1,4 @@ -import assertString from './util/assertString.js'; +import assertString from './util/assertString'; /* eslint-disable prefer-rest-params */ export default function isLength(str, options) { From cdd2192e6a53305d7918eb9263bf5a9332d5fdc9 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 00:36:52 +0530 Subject: [PATCH 03/40] Updated test/validators.js --- test/validators.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/validators.js b/test/validators.js index 87f73ccd4..855f9fea6 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4629,6 +4629,12 @@ describe('Validators', () => { valid: [''], invalid: ['a', 'ab'], }); + test({ + validator: 'isLength', + args: [4], + valid: ['ab', 'abcd', 'cd', 'def'], + invalid: ['', 'a'], + }); }); it('should validate isLocale codes', () => { From 27a40c870189180b0ff1f8948a33b1a97bed4153 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 00:49:45 +0530 Subject: [PATCH 04/40] Fixed in test/validators.js --- test/validators.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/validators.js b/test/validators.js index 855f9fea6..b7ccef54f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4631,9 +4631,9 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [4], - valid: ['ab', 'abcd', 'cd', 'def'], - invalid: ['', 'a'], + args: [2, 4, 6], + valid: ['Helloo', 'Laptop'], + invalid: ['', 'a', 'ab'], }); }); @@ -4704,6 +4704,24 @@ describe('Validators', () => { valid: ['abc', 'de', 'a', ''], invalid: ['abcd'], }); + test({ + validator: 'isLength', + args: [{ max: 6, exact: 5 }], + valid: ['abcde', 'fffde', 'allkk'], + invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], + }); + test({ + validator: 'isLength', + args: [{ min: 2, max: 6, exact: 5 }], + valid: ['abcde', 'fffde', 'allkk'], + invalid: ['bsa', 'vfvd', 'ff', '', 'k'], + }); + test({ + validator: 'isLength', + args: [{ exact: 2 }], + valid: ['fg', 'ff', 'po'], + invalid: ['bsa', 'vfvd', '', 'k'], + }); test({ validator: 'isLength', args: [{ max: 0 }], From cf729d1f3e74dea72845522e28243dd4feef577f Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 00:53:57 +0530 Subject: [PATCH 05/40] Updated test/validators.js for isLength() --- test/validators.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index b7ccef54f..ef66a80ac 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4631,9 +4631,9 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [2, 4, 6], + args: [2, 8, 6], valid: ['Helloo', 'Laptop'], - invalid: ['', 'a', 'ab'], + invalid: ['', 'a', 'ab', 'vjidj'], }); }); From be706c4b7cf5a7a310f03408a9dbff5581524995 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 01:19:52 +0530 Subject: [PATCH 06/40] Updated test/validators.js --- test/validators.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/validators.js b/test/validators.js index ef66a80ac..cb57c85fd 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4635,6 +4635,18 @@ describe('Validators', () => { valid: ['Helloo', 'Laptop'], invalid: ['', 'a', 'ab', 'vjidj'], }); + test({ + validator: 'isLength', + args: [2, 8, [6, 7]], + valid: ['Helloot', 'Laptopr', 'abcdef'], + invalid: ['', 'a', 'ab', 'vjidj'], + }); + test({ + validator: 'isLength', + args: [5, 8, {'one': 6, 'two': 7}], + valid: ['evnvkn', 'fafesfe', 'abcdef'], + invalid: ['', 'a', 'ab', 'vjidj', 'abcdefgh'], + }); }); it('should validate isLocale codes', () => { From db5b0c7761f6abdb3da82fb0f7c7d0f890f392df Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 01:24:34 +0530 Subject: [PATCH 07/40] Updated test/validators.js --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index cb57c85fd..dc21e6b7d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4643,7 +4643,7 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [5, 8, {'one': 6, 'two': 7}], + args: [5, 8, {one: 6, two: 7}], valid: ['evnvkn', 'fafesfe', 'abcdef'], invalid: ['', 'a', 'ab', 'vjidj', 'abcdefgh'], }); From 2e480532e5fb28debe2516f0f1f99a2493f955be Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 01:27:23 +0530 Subject: [PATCH 08/40] Updated test/validators.js --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index dc21e6b7d..b565d65f2 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4643,7 +4643,7 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [5, 8, {one: 6, two: 7}], + args: [5, 8, { one: 6, two: 7 }], valid: ['evnvkn', 'fafesfe', 'abcdef'], invalid: ['', 'a', 'ab', 'vjidj', 'abcdefgh'], }); From c1945260a7394fe445371b9eb04518997a281c39 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 01:37:17 +0530 Subject: [PATCH 09/40] Updated test/validators.js --- test/validators.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/validators.js b/test/validators.js index b565d65f2..4991b733d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4647,6 +4647,12 @@ describe('Validators', () => { valid: ['evnvkn', 'fafesfe', 'abcdef'], invalid: ['', 'a', 'ab', 'vjidj', 'abcdefgh'], }); + test({ + validator: 'isLength', + args: [5, 8, { first: 9, second: 10, third: 8 }], + valid: ['abcdefgh'], + invalid: ['', 'a', 'ab', 'vjidj', 'abcdefghjj', 'hhdjsdv'], + }); }); it('should validate isLocale codes', () => { From 21ec415d185b460942ef61e00bb885afd2423194 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 01:49:31 +0530 Subject: [PATCH 10/40] Updated test/validators.js --- test/validators.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/validators.js b/test/validators.js index 4991b733d..d59eb4cae 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4728,6 +4728,12 @@ describe('Validators', () => { valid: ['abcde', 'fffde', 'allkk'], invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], }); + test({ + validator: 'isLength', + args: [{ max: 6, exact: { } }], + valid: [], + invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], + }); test({ validator: 'isLength', args: [{ min: 2, max: 6, exact: 5 }], From 59abfc75ae769c19ae2686fb0b72ca21d30b1f41 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 01:53:01 +0530 Subject: [PATCH 11/40] Fixed Small Issue --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index d59eb4cae..9adbf0a9c 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4730,7 +4730,7 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [{ max: 6, exact: { } }], + args: [{ max: 6, exact: { } }], valid: [], invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], }); From e1bb810d2cd751acd522165c272a214d861765a5 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 02:07:45 +0530 Subject: [PATCH 12/40] Fixed Small Issue --- src/lib/isLength.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 6ac020a44..7c70e62d1 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -40,6 +40,6 @@ export default function isLength(str, options) { break; } } - } + } else { } return isPerfect; } From 7c2c0cfc7a776c374b6e0da0140d07ee91dba5ab Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 02:11:31 +0530 Subject: [PATCH 13/40] Fixed Small Issue --- src/lib/isLength.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 7c70e62d1..356feec30 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -40,6 +40,6 @@ export default function isLength(str, options) { break; } } - } else { } + } else { ;} return isPerfect; } From 3ee58c0ddff99748361aecceab6bfacf3c6482fa Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 02:13:38 +0530 Subject: [PATCH 14/40] Fixed Small Issue --- src/lib/isLength.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 356feec30..377cf4afa 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -40,6 +40,8 @@ export default function isLength(str, options) { break; } } - } else { ;} + } else { + isPerfect = false; + } return isPerfect; } From d3e6ca547991ab4d136f38a4a29db77897e936c7 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 02:15:48 +0530 Subject: [PATCH 15/40] Fixed Small Issue --- src/lib/isLength.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 377cf4afa..b6db0238f 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -40,8 +40,8 @@ export default function isLength(str, options) { break; } } - } else { - isPerfect = false; + } else { + isPerfect = true; } return isPerfect; } From b850b84cce4e419ba5036cfab2abff5e5308ed5c Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 02:20:03 +0530 Subject: [PATCH 16/40] Fixed Small Issue --- src/lib/isLength.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index b6db0238f..3d3271184 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -37,11 +37,10 @@ export default function isLength(str, options) { for (let key in exact) { if (len === exact[key]) { isPerfect = true; - break; } } } else { - isPerfect = true; + isPerfect = false; } return isPerfect; } From acfe0719b149a0614eeb0cb219bc9225ef983428 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 02:23:16 +0530 Subject: [PATCH 17/40] Updated test/validators.js --- test/validators.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/validators.js b/test/validators.js index 9adbf0a9c..7b2809c82 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4752,6 +4752,12 @@ describe('Validators', () => { valid: [''], invalid: ['a', 'ab'], }); + test({ + validator: 'isLength', + args: [{ max: 6, exact: "5" }], + valid: [''], + invalid: ['a', 'ab'], + }); test({ validator: 'isLength', valid: ['a', '', 'asds'], From cdb06a5720b847f8dea97984f07362a59d969c65 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 02:25:10 +0530 Subject: [PATCH 18/40] Updated test/validators.js --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 7b2809c82..6dd2789b1 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4754,7 +4754,7 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [{ max: 6, exact: "5" }], + args: [{ max: 6, exact: '5' }], valid: [''], invalid: ['a', 'ab'], }); From 70775b4b56ae990959cccb22f3a7c064b6b56370 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 7 Aug 2022 02:30:53 +0530 Subject: [PATCH 19/40] Fixed Small Issue --- test/validators.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/validators.js b/test/validators.js index 6dd2789b1..e5e7f77db 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4641,6 +4641,12 @@ describe('Validators', () => { valid: ['Helloot', 'Laptopr', 'abcdef'], invalid: ['', 'a', 'ab', 'vjidj'], }); + test({ + validator: 'isLength', + args: [2, 8, '9'], + valid: [], + invalid: ['a', 'ab', 'vjidj'], + }); test({ validator: 'isLength', args: [5, 8, { one: 6, two: 7 }], @@ -4752,12 +4758,6 @@ describe('Validators', () => { valid: [''], invalid: ['a', 'ab'], }); - test({ - validator: 'isLength', - args: [{ max: 6, exact: '5' }], - valid: [''], - invalid: ['a', 'ab'], - }); test({ validator: 'isLength', valid: ['a', '', 'asds'], From a71b7ffc903aeda2e34619e0b40d5f8798247d17 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Mon, 8 Aug 2022 17:16:38 +0530 Subject: [PATCH 20/40] Renamed isPerfect to isValid --- src/lib/isLength.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 3d3271184..7297cc9fd 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -7,7 +7,7 @@ export default function isLength(str, options) { let max; let exact; let result; - let isPerfect = false; + let isValid = false; if (typeof (options) === 'object') { min = options.min || 0; max = options.max; @@ -25,22 +25,22 @@ export default function isLength(str, options) { if (Array.isArray(exact) === true) { for (let oneElem of exact) { if (len === oneElem) { - isPerfect = true; + isValid = true; break; } } } else if (typeof exact === 'number') { if (len === exact) { - isPerfect = true; + isValid = true; } } else if (typeof exact === 'object') { for (let key in exact) { if (len === exact[key]) { - isPerfect = true; + isValid = true; } } } else { - isPerfect = false; + isValid = false; } - return isPerfect; + return isValid; } From dc42e7f41895d8c917c9e07a1fd70b712269d44d Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 14 Aug 2022 00:19:56 +0530 Subject: [PATCH 21/40] Removed Backwards Compatibility for exact Feature --- src/lib/isLength.js | 1 - test/validators.js | 38 +++++++++++++------------------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 7297cc9fd..7e44ed64c 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -15,7 +15,6 @@ export default function isLength(str, options) { } else { // backwards compatibility: isLength(str, min [, max]) min = arguments[1] || 0; max = arguments[2]; - exact = arguments[3]; } const presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || []; const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; diff --git a/test/validators.js b/test/validators.js index e5e7f77db..5296ddac1 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4631,34 +4631,10 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [2, 8, 6], + args: [2, 8], valid: ['Helloo', 'Laptop'], invalid: ['', 'a', 'ab', 'vjidj'], }); - test({ - validator: 'isLength', - args: [2, 8, [6, 7]], - valid: ['Helloot', 'Laptopr', 'abcdef'], - invalid: ['', 'a', 'ab', 'vjidj'], - }); - test({ - validator: 'isLength', - args: [2, 8, '9'], - valid: [], - invalid: ['a', 'ab', 'vjidj'], - }); - test({ - validator: 'isLength', - args: [5, 8, { one: 6, two: 7 }], - valid: ['evnvkn', 'fafesfe', 'abcdef'], - invalid: ['', 'a', 'ab', 'vjidj', 'abcdefgh'], - }); - test({ - validator: 'isLength', - args: [5, 8, { first: 9, second: 10, third: 8 }], - valid: ['abcdefgh'], - invalid: ['', 'a', 'ab', 'vjidj', 'abcdefghjj', 'hhdjsdv'], - }); }); it('should validate isLocale codes', () => { @@ -4758,6 +4734,18 @@ describe('Validators', () => { valid: [''], invalid: ['a', 'ab'], }); + test({ + validator: 'isLength', + args: [{ min: 5, max: 10, exact: [6, 8, 9] }], + valid: ['helloguy', 'shopping', 'validator', 'length'], + invalid: ['abcde', 'abcdefg'], + }); + test({ + validator: 'isLength', + args: [{ min: 5, max: 10, exact: { first: 6, second: 8, third: 9} }], + valid: ['helloguy', 'shopping', 'validator', 'length'], + invalid: ['abcde', 'abcdefg', 'abcdefghij'], + }); test({ validator: 'isLength', valid: ['a', '', 'asds'], From fb0def3970c6920d99670ba6033778b27a5e9d32 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 14 Aug 2022 00:22:35 +0530 Subject: [PATCH 22/40] Fixed Minor Bug --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 5296ddac1..f99c9fe2b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4742,7 +4742,7 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [{ min: 5, max: 10, exact: { first: 6, second: 8, third: 9} }], + args: [{ min: 5, max: 10, exact: { first: 6, second: 8, third: 9 } }], valid: ['helloguy', 'shopping', 'validator', 'length'], invalid: ['abcde', 'abcdefg', 'abcdefghij'], }); From ec1aa917a1edbc7d39948f1314faa705bd66dc0e Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 14 Aug 2022 00:28:05 +0530 Subject: [PATCH 23/40] Fixed Small Issue --- test/validators.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index f99c9fe2b..43e4fe2ff 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4632,8 +4632,8 @@ describe('Validators', () => { test({ validator: 'isLength', args: [2, 8], - valid: ['Helloo', 'Laptop'], - invalid: ['', 'a', 'ab', 'vjidj'], + valid: ['Helloo', 'Laptop', 'ab'], + invalid: ['', 'a'], }); }); From 73dc5056310d5b87963c5546e96df0395864337e Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 14 Aug 2022 00:33:18 +0530 Subject: [PATCH 24/40] Fixed Small Issue --- test/validators.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/validators.js b/test/validators.js index 43e4fe2ff..f7aee71f5 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4746,6 +4746,12 @@ describe('Validators', () => { valid: ['helloguy', 'shopping', 'validator', 'length'], invalid: ['abcde', 'abcdefg', 'abcdefghij'], }); + test({ + validator: 'isLength', + args: [{ exact: '9' }], + valid: [], + invalid: ['a', 'abcd', 'abcdefghijkl'], + }); test({ validator: 'isLength', valid: ['a', '', 'asds'], From c7605bcbe64ff039d11ae62c31da3f4c401b8b2c Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 14 Aug 2022 02:28:04 +0530 Subject: [PATCH 25/40] Updated README.md, isLength.js & validators.js Files --- README.md | 2 +- src/lib/isLength.js | 2 -- test/validators.js | 8 +------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1ed947944..6f60cee5b 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Validator | Description **isJSON(str [, options])** | check if the string is valid JSON (note: uses JSON.parse).

`options` is an object which defaults to `{ allow_primitives: false }`. If `allow_primitives` is true, the primitives 'true', 'false' and 'null' are accepted as valid JSON values. **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`.

`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 and equal to exactValue if provided.

`options` is an object which defaults to `{min:0, max: undefined, exact: undefined}`. Note: this function takes into account surrogate pairs. +**isLength(str [, options])** | check if the string's length falls in a range and equal to `exact` if provided. The `exact` can be an integer, an array or an object of several integers.

`options` is an object which defaults to `{min:0, max: undefined, exact: undefined}`. Note: this function takes into account surrogate pairs. **isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'fi-FI', 'pt-BR', 'pt-PT', 'sq-AL', 'sv-SE', 'en-IN', 'hi-IN', 'gu-IN', 'as-IN', 'bn-IN', 'kn-IN', 'ml-IN', 'mr-IN', 'or-IN', 'pa-IN', 'sa-IN', 'ta-IN', 'te-IN', 'kok-IN']` or `any`) **isLocale(str)** | check if the string is a locale **isLowercase(str)** | check if the string is lowercase. diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 7e44ed64c..580a9ee78 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -38,8 +38,6 @@ export default function isLength(str, options) { isValid = true; } } - } else { - isValid = false; } return isValid; } diff --git a/test/validators.js b/test/validators.js index f7aee71f5..b09d9a95e 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4629,12 +4629,6 @@ describe('Validators', () => { valid: [''], invalid: ['a', 'ab'], }); - test({ - validator: 'isLength', - args: [2, 8], - valid: ['Helloo', 'Laptop', 'ab'], - invalid: ['', 'a'], - }); }); it('should validate isLocale codes', () => { @@ -4724,7 +4718,7 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [{ exact: 2 }], + args: [{ min: 1, exact: 2 }], valid: ['fg', 'ff', 'po'], invalid: ['bsa', 'vfvd', '', 'k'], }); From 93ac65f124f76e4f862f9cea80bd7462a9051314 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 14 Aug 2022 02:38:59 +0530 Subject: [PATCH 26/40] Updated validators.js in test Folder --- test/validators.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/validators.js b/test/validators.js index b09d9a95e..e0c6c96ff 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4623,12 +4623,6 @@ describe('Validators', () => { valid: ['干𩸽', '𠮷野家'], invalid: ['', '𠀋', '千竈通り'], }); - test({ - validator: 'isLength', - args: [0, 0], - valid: [''], - invalid: ['a', 'ab'], - }); }); it('should validate isLocale codes', () => { From bc693dc5a97685a63a329119699416b370900443 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 14 Aug 2022 02:54:58 +0530 Subject: [PATCH 27/40] Included exact out of range Test --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index e0c6c96ff..e01870241 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4724,7 +4724,7 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [{ min: 5, max: 10, exact: [6, 8, 9] }], + args: [{ min: 5, max: 10, exact: [2, 6, 8, 9] }], valid: ['helloguy', 'shopping', 'validator', 'length'], invalid: ['abcde', 'abcdefg'], }); From a90171f83817f0101c79b151df259f4cd446a08c Mon Sep 17 00:00:00 2001 From: Vatsal Date: Mon, 15 Aug 2022 02:20:52 +0530 Subject: [PATCH 28/40] Added Additional Test in validators.js for isLength --- test/validators.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/validators.js b/test/validators.js index e01870241..d6bda7bf8 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4623,6 +4623,12 @@ describe('Validators', () => { valid: ['干𩸽', '𠮷野家'], invalid: ['', '𠀋', '千竈通り'], }); + test({ + validator: 'isLength', + args: [0, 0], + valid: [''], + invalid: ['a', 'ab'], + }); }); it('should validate isLocale codes', () => { From 57a5633b82f1401ce5e32a77d4d549a77df6340e Mon Sep 17 00:00:00 2001 From: Vatsal Sanchala Date: Sat, 12 Nov 2022 22:00:29 +0530 Subject: [PATCH 29/40] Update src/lib/isLength.js Improvement update Co-authored-by: Falk Schieber <12937991+pixelbucket-dev@users.noreply.github.com> --- src/lib/isLength.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 580a9ee78..acca8d058 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -20,7 +20,14 @@ export default function isLength(str, options) { const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; const len = str.length - presentationSequences.length - surrogatePairs.length; result = len >= min && (typeof max === 'undefined' || len <= max); - if (result === false || typeof exact === 'undefined') return result; +const isInsideRange = +len >= min && (typeof max === 'undefined' || len <= max); + +if (isInsideRange && Array.isArray(options?.discreteLengths)) { + return options.discreteLengths.some(discreteLen => discreteLen === len); +} + +return isInsideRange; if (Array.isArray(exact) === true) { for (let oneElem of exact) { if (len === oneElem) { From 642e603053aee6d96e6d3db2f32e9ccba4b64786 Mon Sep 17 00:00:00 2001 From: Vatsal Sanchala Date: Sat, 12 Nov 2022 22:05:14 +0530 Subject: [PATCH 30/40] Update isLength.js --- src/lib/isLength.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index acca8d058..f00dd19ce 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -28,23 +28,3 @@ if (isInsideRange && Array.isArray(options?.discreteLengths)) { } return isInsideRange; - if (Array.isArray(exact) === true) { - for (let oneElem of exact) { - if (len === oneElem) { - isValid = true; - break; - } - } - } else if (typeof exact === 'number') { - if (len === exact) { - isValid = true; - } - } else if (typeof exact === 'object') { - for (let key in exact) { - if (len === exact[key]) { - isValid = true; - } - } - } - return isValid; -} From bb02dafb250cfe6c3d9ae99621f1b5a268b85263 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sat, 12 Nov 2022 22:17:31 +0530 Subject: [PATCH 31/40] Updated discreteLengths only to be array --- README.md | 2 +- src/lib/isLength.js | 28 ++++------------------------ test/validators.js | 26 +++++++------------------- 3 files changed, 12 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 6f60cee5b..4a791bfac 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Validator | Description **isJSON(str [, options])** | check if the string is valid JSON (note: uses JSON.parse).

`options` is an object which defaults to `{ allow_primitives: false }`. If `allow_primitives` is true, the primitives 'true', 'false' and 'null' are accepted as valid JSON values. **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`.

`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 and equal to `exact` if provided. The `exact` can be an integer, an array or an object of several integers.

`options` is an object which defaults to `{min:0, max: undefined, exact: undefined}`. Note: this function takes into account surrogate pairs. +**isLength(str [, options])** | check if the string's length falls in a range and equal to any of the integers of the `discreteLengths` array if provided.

`options` is an object which defaults to `{min:0, max: undefined, discreteLengths: undefined}`. Note: this function takes into account surrogate pairs. **isLicensePlate(str [, locale])** | check if string matches the format of a country's license plate.

(locale is one of `['cs-CZ', 'de-DE', 'de-LI', 'fi-FI', 'pt-BR', 'pt-PT', 'sq-AL', 'sv-SE', 'en-IN', 'hi-IN', 'gu-IN', 'as-IN', 'bn-IN', 'kn-IN', 'ml-IN', 'mr-IN', 'or-IN', 'pa-IN', 'sa-IN', 'ta-IN', 'te-IN', 'kok-IN']` or `any`) **isLocale(str)** | check if the string is a locale **isLowercase(str)** | check if the string is lowercase. diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 580a9ee78..a2630433c 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -5,13 +5,9 @@ export default function isLength(str, options) { assertString(str); let min; let max; - let exact; - let result; - let isValid = false; if (typeof (options) === 'object') { min = options.min || 0; max = options.max; - exact = options.exact; } else { // backwards compatibility: isLength(str, min [, max]) min = arguments[1] || 0; max = arguments[2]; @@ -19,25 +15,9 @@ export default function isLength(str, options) { const presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || []; const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; const len = str.length - presentationSequences.length - surrogatePairs.length; - result = len >= min && (typeof max === 'undefined' || len <= max); - if (result === false || typeof exact === 'undefined') return result; - if (Array.isArray(exact) === true) { - for (let oneElem of exact) { - if (len === oneElem) { - isValid = true; - break; - } - } - } else if (typeof exact === 'number') { - if (len === exact) { - isValid = true; - } - } else if (typeof exact === 'object') { - for (let key in exact) { - if (len === exact[key]) { - isValid = true; - } - } + const isInsideRange = len >= min && (typeof max === 'undefined' || len <= max); + if (isInsideRange && Array.isArray(options?.discreteLengths)) { + return options.discreteLengths.some(discreteLen => discreteLen === len); } - return isValid; + return isInsideRange; } diff --git a/test/validators.js b/test/validators.js index d6bda7bf8..561d7c2f5 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4700,26 +4700,20 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [{ max: 6, exact: 5 }], - valid: ['abcde', 'fffde', 'allkk'], - invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], - }); - test({ - validator: 'isLength', - args: [{ max: 6, exact: { } }], + args: [{ max: 6, discreteLengths: 5 }], valid: [], invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], }); test({ validator: 'isLength', - args: [{ min: 2, max: 6, exact: 5 }], - valid: ['abcde', 'fffde', 'allkk'], + args: [{ min: 2, max: 6, discreteLengths: 5 }], + valid: [], invalid: ['bsa', 'vfvd', 'ff', '', 'k'], }); test({ validator: 'isLength', - args: [{ min: 1, exact: 2 }], - valid: ['fg', 'ff', 'po'], + args: [{ min: 1, discreteLengths: 2 }], + valid: [], invalid: ['bsa', 'vfvd', '', 'k'], }); test({ @@ -4730,19 +4724,13 @@ describe('Validators', () => { }); test({ validator: 'isLength', - args: [{ min: 5, max: 10, exact: [2, 6, 8, 9] }], + args: [{ min: 5, max: 10, discreteLengths: [2, 6, 8, 9] }], valid: ['helloguy', 'shopping', 'validator', 'length'], invalid: ['abcde', 'abcdefg'], }); test({ validator: 'isLength', - args: [{ min: 5, max: 10, exact: { first: 6, second: 8, third: 9 } }], - valid: ['helloguy', 'shopping', 'validator', 'length'], - invalid: ['abcde', 'abcdefg', 'abcdefghij'], - }); - test({ - validator: 'isLength', - args: [{ exact: '9' }], + args: [{ discreteLengths: '9' }], valid: [], invalid: ['a', 'abcd', 'abcdefghijkl'], }); From 1bf1ee4142c4d520cd9d94e140b96a54578e92a2 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sat, 12 Nov 2022 22:28:05 +0530 Subject: [PATCH 32/40] Fixed minor bug --- src/lib/isLength.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 7bc0d074f..d5dcbd1ae 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -20,3 +20,4 @@ export default function isLength(str, options) { return options.discreteLengths.some(discreteLen =>discreteLen === len); } return isInsideRange; +} From 9fd65ed2386a46abaa4b2a312915e896681c49c5 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sat, 12 Nov 2022 22:32:07 +0530 Subject: [PATCH 33/40] Fixed minor bug --- src/lib/isLength.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index d5dcbd1ae..a2630433c 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -17,7 +17,7 @@ export default function isLength(str, options) { const len = str.length - presentationSequences.length - surrogatePairs.length; const isInsideRange = len >= min && (typeof max === 'undefined' || len <= max); if (isInsideRange && Array.isArray(options?.discreteLengths)) { - return options.discreteLengths.some(discreteLen =>discreteLen === len); + return options.discreteLengths.some(discreteLen => discreteLen === len); } return isInsideRange; } From fd906915c7299febf1a662389725fd8c690158de Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sat, 12 Nov 2022 22:46:08 +0530 Subject: [PATCH 34/40] Fixed tests for isLength --- test/validators.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/validators.js b/test/validators.js index 561d7c2f5..65bd78b54 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4701,20 +4701,20 @@ describe('Validators', () => { test({ validator: 'isLength', args: [{ max: 6, discreteLengths: 5 }], - valid: [], - invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], + valid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], + invalid: ['hfjdksks'], }); test({ validator: 'isLength', args: [{ min: 2, max: 6, discreteLengths: 5 }], - valid: [], - invalid: ['bsa', 'vfvd', 'ff', '', 'k'], + valid: ['bsa', 'vfvd', 'ff', '', 'k'], + invalid: ['', ' ', 'hfskdunvc'], }); test({ validator: 'isLength', args: [{ min: 1, discreteLengths: 2 }], - valid: [], - invalid: ['bsa', 'vfvd', '', 'k'], + valid: [''], + invalid: ['bsa'], }); test({ validator: 'isLength', From d09738c3331da6a7ff3071b5acc4a47ddb248f60 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sat, 12 Nov 2022 22:50:09 +0530 Subject: [PATCH 35/40] Fixed minor bug --- test/validators.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/validators.js b/test/validators.js index 65bd78b54..cde213503 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4701,19 +4701,19 @@ describe('Validators', () => { test({ validator: 'isLength', args: [{ max: 6, discreteLengths: 5 }], - valid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k'], - invalid: ['hfjdksks'], + valid: [], + invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k', 'hfjdksks'], }); test({ validator: 'isLength', args: [{ min: 2, max: 6, discreteLengths: 5 }], - valid: ['bsa', 'vfvd', 'ff', '', 'k'], + valid: ['bsa', 'vfvd', 'ff'], invalid: ['', ' ', 'hfskdunvc'], }); test({ validator: 'isLength', args: [{ min: 1, discreteLengths: 2 }], - valid: [''], + valid: [' ', 'hello'], invalid: ['bsa'], }); test({ @@ -4731,8 +4731,8 @@ describe('Validators', () => { test({ validator: 'isLength', args: [{ discreteLengths: '9' }], - valid: [], - invalid: ['a', 'abcd', 'abcdefghijkl'], + valid: ['a', 'abcd', 'abcdefghijkl'], + invalid: [], }); test({ validator: 'isLength', From 11aa19fb14847619953d43526af2fd06cd915a2b Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 13 Nov 2022 14:01:13 +0530 Subject: [PATCH 36/40] Minor test bug fixed --- test/validators.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index cde213503..ba131087e 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4713,8 +4713,8 @@ describe('Validators', () => { test({ validator: 'isLength', args: [{ min: 1, discreteLengths: 2 }], - valid: [' ', 'hello'], - invalid: ['bsa'], + valid: [' ', 'hello', 'bsa'], + invalid: [''], }); test({ validator: 'isLength', From e63e7a536c0d833fb2e3122eb4a93d1c665b34c2 Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sun, 13 Nov 2022 14:43:27 +0530 Subject: [PATCH 37/40] Fixed minor bug in test/validator.js --- src/lib/isLength.js | 2 +- test/validators.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index a2630433c..eb48ece58 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -15,7 +15,7 @@ export default function isLength(str, options) { const presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || []; const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; const len = str.length - presentationSequences.length - surrogatePairs.length; - const isInsideRange = len >= min && (typeof max === 'undefined' || len <= max); + const isInsideRange = (len >= min && (typeof max === 'undefined' || len <= max)); if (isInsideRange && Array.isArray(options?.discreteLengths)) { return options.discreteLengths.some(discreteLen => discreteLen === len); } diff --git a/test/validators.js b/test/validators.js index ba131087e..36a758ca0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -4701,8 +4701,8 @@ describe('Validators', () => { test({ validator: 'isLength', args: [{ max: 6, discreteLengths: 5 }], - valid: [], - invalid: ['abcd', 'abcdef', 'vfd', 'ff', '', 'k', 'hfjdksks'], + valid: ['abcd', 'vfd', 'ff', '', 'k'], + invalid: ['abcdefgh', 'hfjdksks'], }); test({ validator: 'isLength', From 3b5cbd9808216f079ad41c705205ac204a86696d Mon Sep 17 00:00:00 2001 From: Vatsal Sanchala Date: Fri, 18 Nov 2022 23:59:00 +0530 Subject: [PATCH 38/40] Update src/lib/isLength.js Co-authored-by: Falk Schieber <12937991+pixelbucket-dev@users.noreply.github.com> --- src/lib/isLength.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index eb48ece58..64db5b9c9 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -15,7 +15,13 @@ export default function isLength(str, options) { const presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || []; const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; const len = str.length - presentationSequences.length - surrogatePairs.length; - const isInsideRange = (len >= min && (typeof max === 'undefined' || len <= max)); + const isInsideRange = len >= min && (typeof max === 'undefined' || len <= max); + + if (isInsideRange && Array.isArray(options?.discreteLengths)) { + return options.discreteLengths.some(discreteLen => discreteLen === len); + } + + return isInsideRange; if (isInsideRange && Array.isArray(options?.discreteLengths)) { return options.discreteLengths.some(discreteLen => discreteLen === len); } From 2897ef935bb15b24ed8fd6bb739f51c4828a696a Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sat, 19 Nov 2022 00:13:53 +0530 Subject: [PATCH 39/40] Added blank lines between statements --- src/lib/isLength.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 64db5b9c9..6f8d90aaf 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -5,6 +5,7 @@ export default function isLength(str, options) { assertString(str); let min; let max; + if (typeof (options) === 'object') { min = options.min || 0; max = options.max; @@ -12,6 +13,7 @@ export default function isLength(str, options) { min = arguments[1] || 0; max = arguments[2]; } + const presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || []; const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; const len = str.length - presentationSequences.length - surrogatePairs.length; @@ -21,9 +23,5 @@ export default function isLength(str, options) { return options.discreteLengths.some(discreteLen => discreteLen === len); } - return isInsideRange; - if (isInsideRange && Array.isArray(options?.discreteLengths)) { - return options.discreteLengths.some(discreteLen => discreteLen === len); - } return isInsideRange; } From 22bb2f0b14238fa1d65e1c8d390883dddfe6adcf Mon Sep 17 00:00:00 2001 From: Vatsal Date: Sat, 19 Nov 2022 00:16:55 +0530 Subject: [PATCH 40/40] Updated isLength.js --- src/lib/isLength.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/isLength.js b/src/lib/isLength.js index 6f8d90aaf..3ca7d339c 100644 --- a/src/lib/isLength.js +++ b/src/lib/isLength.js @@ -13,13 +13,13 @@ export default function isLength(str, options) { min = arguments[1] || 0; max = arguments[2]; } - + const presentationSequences = str.match(/(\uFE0F|\uFE0E)/g) || []; const surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; const len = str.length - presentationSequences.length - surrogatePairs.length; const isInsideRange = len >= min && (typeof max === 'undefined' || len <= max); - if (isInsideRange && Array.isArray(options?.discreteLengths)) { + if (isInsideRange && Array.isArray(options?.discreteLengths)){ return options.discreteLengths.some(discreteLen => discreteLen === len); }