From c38fdc383f40784efa2f14762823bfe0ca2c1a80 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Tue, 15 Oct 2019 23:48:28 +0900 Subject: [PATCH 01/22] isHSL WIP --- src/index.js | 2 ++ src/lib/isHSL.js | 8 ++++++++ test/validators.js | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 src/lib/isHSL.js diff --git a/src/index.js b/src/index.js index f96d4c1ee..e6e999aa6 100644 --- a/src/index.js +++ b/src/index.js @@ -37,6 +37,7 @@ import isOctal from './lib/isOctal'; import isDivisibleBy from './lib/isDivisibleBy'; import isHexColor from './lib/isHexColor'; +import isHSL from './lib/isHSL'; import isISRC from './lib/isISRC'; @@ -139,6 +140,7 @@ const validator = { isOctal, isDivisibleBy, isHexColor, + isHSL, isISRC, isMD5, isHash, diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js new file mode 100644 index 000000000..197f5422f --- /dev/null +++ b/src/lib/isHSL.js @@ -0,0 +1,8 @@ +import assertString from './util/assertString'; + +const hsl = /^(hsl)\(\s*0*([0-2]?[0-9]?[0-9]|3[0-5][0-9]|360)\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*\)$/i; + +export default function isHSL(str) { + assertString(str); + return hsl.test(str); +} diff --git a/test/validators.js b/test/validators.js index 3bae22e9d..627cc5b66 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2551,6 +2551,27 @@ describe('Validators', () => { }); }); + it('should validate HSL color strings', () => { + test({ + validator: 'isHSL', + valid: [ + 'hsl(360,0000000000100%,000000100%)', + 'HSL(00000,0000000000100%,000000100%)', + 'hsL(0, 0%, 0%)', + 'hSl( 360 , 100% , 100% )', + 'Hsl( 00150 , 000099% , 01% )', + ], + invalid: [ + 'hsl (360,0000000000100%,000000100%)', + 'hsl(361, 100%, 100%)', + 'hsl(0260, 101%, 100%)', + 'hsl(0160, 100%, 101%)', + 'hsl(0160, -100%, 101%)', + 'hsl(-0160, 100%, 101%)', + ], + }); + }); + it('should validate ISRC code strings', () => { test({ validator: 'isISRC', From 067f03c9c6796c759e0a865fe37d7167d7b79937 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Tue, 15 Oct 2019 23:52:06 +0900 Subject: [PATCH 02/22] Added another valid test case. --- test/validators.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/validators.js b/test/validators.js index 627cc5b66..5cdd64914 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2556,6 +2556,7 @@ describe('Validators', () => { validator: 'isHSL', valid: [ 'hsl(360,0000000000100%,000000100%)', + 'hsl(000010, 00000000001%, 00000040%)', 'HSL(00000,0000000000100%,000000100%)', 'hsL(0, 0%, 0%)', 'hSl( 360 , 100% , 100% )', From 6783382b9c74356539946c980385709dca11cfa6 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Wed, 16 Oct 2019 00:03:34 +0900 Subject: [PATCH 03/22] Updated readme to include isHSL. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6273ea12e..1d2f8c1a4 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ Validator | Description **isHash(str, algorithm)** | check if the string is a hash of type algorithm.

Algorithm is one of `['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']` **isHexadecimal(str)** | check if the string is a hexadecimal number. **isHexColor(str)** | check if the string is a hexadecimal color. +**isHSL(str)** | check if the string is an HSL (hue, saturation, lightness) color. **isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'zh-TW', 'he-IL']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIn(str, values)** | check if the string is in a array of allowed values. **isInt(str [, options])** | check if the string is an integer.

`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4). From 0a71904d37820fbb496831fe76ef10576f4c0050 Mon Sep 17 00:00:00 2001 From: Christopher Ayala Date: Fri, 27 Dec 2019 22:32:47 +0900 Subject: [PATCH 04/22] WIP on validating degree values beyond [0,360] --- src/lib/isHSL.js | 2 +- test/validators.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 197f5422f..2a7fe7542 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,6 +1,6 @@ import assertString from './util/assertString'; -const hsl = /^(hsl)\(\s*0*([0-2]?[0-9]?[0-9]|3[0-5][0-9]|360)\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*\)$/i; +const hsl = /^(hsl)\(\s*(\+|\-)?0*[0-9]+\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*\)$/i; export default function isHSL(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index ee041bdd3..2b72b6b14 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2609,14 +2609,19 @@ describe('Validators', () => { 'hsL(0, 0%, 0%)', 'hSl( 360 , 100% , 100% )', 'Hsl( 00150 , 000099% , 01% )', + 'hsl(01080, 03%, 4%)', + 'hsl(-540, 03%, 4%)', + 'hsl(540, 03%, 4%)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', - 'hsl(361, 100%, 100%)', 'hsl(0260, 101%, 100%)', 'hsl(0160, 100%, 101%)', 'hsl(0160, -100%, 101%)', - 'hsl(-0160, 100%, 101%)', + 'hsl(-0160, 100$, 100%)', + 'hsl(-0160, 100%, 100a)', + 'hsl(-0160, 1000%, 101%)', + 'hsl(-0160, 100%, -101%)', ], }); }); From dc0b34b6eda1ea9c1fb42a4ad2f8fe98f56d6890 Mon Sep 17 00:00:00 2001 From: Christopher Ayala Date: Fri, 27 Dec 2019 22:43:30 +0900 Subject: [PATCH 05/22] Added + sign test case --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index 2b72b6b14..d67930e5f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2611,7 +2611,7 @@ describe('Validators', () => { 'Hsl( 00150 , 000099% , 01% )', 'hsl(01080, 03%, 4%)', 'hsl(-540, 03%, 4%)', - 'hsl(540, 03%, 4%)', + 'hsl(+540, 03%, 4%)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', From cd611f2436af50f4623a2683deb0748ed147d166 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sat, 22 Feb 2020 21:43:33 +0900 Subject: [PATCH 06/22] More comprehensive HSL check WIP --- src/lib/isHSL.js | 6 ++++-- test/validators.js | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 2a7fe7542..0f0381b0d 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,8 +1,10 @@ import assertString from './util/assertString'; -const hsl = /^(hsl)\(\s*(\+|\-)?0*[0-9]+\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*\)$/i; + +const hslcomma = /^(hsl)a?\(\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?(deg|grad|rad|turn)?)\s*,\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*,\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*(,\s*(((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%?)\s*)?\)$/i; +const hslspace = /^(hsl)a?\(\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?(deg|grad|rad|turn)?)\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*\/\s*((((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%?)\s*)?\)$/i; export default function isHSL(str) { assertString(str); - return hsl.test(str); + return hslcomma.test(str) || hslspace.test(str); } diff --git a/test/validators.js b/test/validators.js index 6dee1781d..4412f9e72 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3139,6 +3139,7 @@ describe('Validators', () => { 'hsl(01080, 03%, 4%)', 'hsl(-540, 03%, 4%)', 'hsl(+540, 03%, 4%)', + 'hsl(+540, 03%, 4%, 500)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', From 4315d0062c49941e99ba956e7ad1d95310767707 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sun, 23 Feb 2020 00:08:51 +0900 Subject: [PATCH 07/22] WIP, new tests are needed. --- src/lib/isHSL.js | 4 ++-- test/validators.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 0f0381b0d..8142ffb82 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,8 +1,8 @@ import assertString from './util/assertString'; -const hslcomma = /^(hsl)a?\(\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?(deg|grad|rad|turn)?)\s*,\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*,\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*(,\s*(((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%?)\s*)?\)$/i; -const hslspace = /^(hsl)a?\(\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?(deg|grad|rad|turn)?)\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*\/\s*((((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%?)\s*)?\)$/i; +const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; export default function isHSL(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index 4412f9e72..7155f0ea9 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3140,6 +3140,17 @@ describe('Validators', () => { 'hsl(-540, 03%, 4%)', 'hsl(+540, 03%, 4%)', 'hsl(+540, 03%, 4%, 500)', + 'hsl(+540deg, 03%, 4%, 500)', + 'hsl(+540gRaD, 03%, 4%, 500)', + 'hsl(+540.01e-98rad, 03%, 4%, 500)', + 'hsl(-540.5turn, 03%, 4%, 500)', + 'hsl(+540, 03%, 4%, 500e-01)', + 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(200grad+.1%62%/1)', + 'hsl(200grad +.1% 62% / 1)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', From 6e0b3312e7b2eea3195a3064b8cdc74ec2577311 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sun, 23 Feb 2020 00:13:45 +0900 Subject: [PATCH 08/22] Added ezkemboi test cases --- test/validators.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/validators.js b/test/validators.js index 7155f0ea9..f764fe4af 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3146,9 +3146,10 @@ describe('Validators', () => { 'hsl(-540.5turn, 03%, 4%, 500)', 'hsl(+540, 03%, 4%, 500e-01)', 'hsl(+540, 03%, 4%, 500e+80)', - 'hsl(+540, 03%, 4%, 500e+80)', - 'hsl(+540, 03%, 4%, 500e+80)', - 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(4.71239rad, 60%, 70%)', + 'hsl(270deg, 60%, 70%)', + 'hsl(270 60% 70%)', + 'hsl(.75turn, 60%, 70%)', 'hsl(200grad+.1%62%/1)', 'hsl(200grad +.1% 62% / 1)', ], From c90164a1ce9394a0f83cd685ef87f4a95b29255a Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sun, 23 Feb 2020 00:23:56 +0900 Subject: [PATCH 09/22] Added ezkemboi test cases --- src/lib/isHSL.js | 4 ++-- test/validators.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 8142ffb82..0b5ff3bc0 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,8 +1,8 @@ import assertString from './util/assertString'; -const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; -const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; export default function isHSL(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index f764fe4af..12b2c1fa0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3152,6 +3152,7 @@ describe('Validators', () => { 'hsl(.75turn, 60%, 70%)', 'hsl(200grad+.1%62%/1)', 'hsl(200grad +.1% 62% / 1)', + 'hsl(200+.1%62%/1)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', From 5b5beccc18728e1ef08b2a6dda87c45e284554df Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sun, 23 Feb 2020 01:38:01 +0900 Subject: [PATCH 10/22] Added ezkemboi test cases --- src/lib/isHSL.js | 2 +- test/validators.js | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 0b5ff3bc0..b4f446334 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -2,7 +2,7 @@ import assertString from './util/assertString'; const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; -const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; export default function isHSL(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index 12b2c1fa0..d87a1889e 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3138,8 +3138,8 @@ describe('Validators', () => { 'Hsl( 00150 , 000099% , 01% )', 'hsl(01080, 03%, 4%)', 'hsl(-540, 03%, 4%)', - 'hsl(+540, 03%, 4%)', - 'hsl(+540, 03%, 4%, 500)', + 'hsla(+540, 03%, 4%)', + 'hsla(+540, 03%, 4%, 500)', 'hsl(+540deg, 03%, 4%, 500)', 'hsl(+540gRaD, 03%, 4%, 500)', 'hsl(+540.01e-98rad, 03%, 4%, 500)', @@ -3148,21 +3148,28 @@ describe('Validators', () => { 'hsl(+540, 03%, 4%, 500e+80)', 'hsl(4.71239rad, 60%, 70%)', 'hsl(270deg, 60%, 70%)', + 'hsl(200, +.1%, 62%, 1)', 'hsl(270 60% 70%)', + 'hsl(200, +.1e-9%, 62e10%, 1)', 'hsl(.75turn, 60%, 70%)', - 'hsl(200grad+.1%62%/1)', + // 'hsl(200grad+.1%62%/1)', //supposed to pass, but need to handle delimiters 'hsl(200grad +.1% 62% / 1)', - 'hsl(200+.1%62%/1)', + 'hsl(270, 60%, 50%, .15)', + 'hsl(270, 60%, 50%, 15%)', + 'hsl(270 60% 50% / .15)', + 'hsl(270 60% 50% / 15%)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', - 'hsl(0260, 101%, 100%)', - 'hsl(0160, 100%, 101%)', - 'hsl(0160, -100%, 101%)', - 'hsl(-0160, 100$, 100%)', + 'hsl(0260, 100 %, 100%)', + 'hsl(0160, 100%, 100%, 100 %)', 'hsl(-0160, 100%, 100a)', - 'hsl(-0160, 1000%, 101%)', - 'hsl(-0160, 100%, -101%)', + 'hsl(-0160, 100%, 100)', + 'hsl(-0160 100%, 100%, )', + 'hsl(270 deg, 60%, 70%)', + 'hsl( deg, 60%, 70%)', + 'hsl(, 60%, 70%)', + 'hsl(3000deg, 70%)', ], }); }); From 71966a4f2534ecc880dfe08e2fec551c3acaadbe Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Tue, 15 Oct 2019 23:48:28 +0900 Subject: [PATCH 11/22] isHSL WIP --- src/index.js | 2 ++ src/lib/isHSL.js | 8 ++++++++ test/validators.js | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 src/lib/isHSL.js diff --git a/src/index.js b/src/index.js index 68645f78e..42549f1b4 100644 --- a/src/index.js +++ b/src/index.js @@ -41,6 +41,7 @@ import isDivisibleBy from './lib/isDivisibleBy'; import isHexColor from './lib/isHexColor'; import isRgbColor from './lib/isRgbColor'; +import isHSL from './lib/isHSL'; import isISRC from './lib/isISRC'; @@ -155,6 +156,7 @@ const validator = { isDivisibleBy, isHexColor, isRgbColor, + isHSL, isISRC, isMD5, isHash, diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js new file mode 100644 index 000000000..197f5422f --- /dev/null +++ b/src/lib/isHSL.js @@ -0,0 +1,8 @@ +import assertString from './util/assertString'; + +const hsl = /^(hsl)\(\s*0*([0-2]?[0-9]?[0-9]|3[0-5][0-9]|360)\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*\)$/i; + +export default function isHSL(str) { + assertString(str); + return hsl.test(str); +} diff --git a/test/validators.js b/test/validators.js index b5e413403..4af82921b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3126,6 +3126,27 @@ describe('Validators', () => { }); }); + it('should validate HSL color strings', () => { + test({ + validator: 'isHSL', + valid: [ + 'hsl(360,0000000000100%,000000100%)', + 'HSL(00000,0000000000100%,000000100%)', + 'hsL(0, 0%, 0%)', + 'hSl( 360 , 100% , 100% )', + 'Hsl( 00150 , 000099% , 01% )', + ], + invalid: [ + 'hsl (360,0000000000100%,000000100%)', + 'hsl(361, 100%, 100%)', + 'hsl(0260, 101%, 100%)', + 'hsl(0160, 100%, 101%)', + 'hsl(0160, -100%, 101%)', + 'hsl(-0160, 100%, 101%)', + ], + }); + }); + it('should validate rgb color strings', () => { test({ validator: 'isRgbColor', From b7f2c1930f078ff2a5486dea339b2ecb5fccc31d Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Tue, 15 Oct 2019 23:52:06 +0900 Subject: [PATCH 12/22] Added another valid test case. --- test/validators.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/validators.js b/test/validators.js index 4af82921b..5c8832ea0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3131,6 +3131,7 @@ describe('Validators', () => { validator: 'isHSL', valid: [ 'hsl(360,0000000000100%,000000100%)', + 'hsl(000010, 00000000001%, 00000040%)', 'HSL(00000,0000000000100%,000000100%)', 'hsL(0, 0%, 0%)', 'hSl( 360 , 100% , 100% )', From 42d4342014320eaf13718a3b3e5c829d21f884de Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Wed, 16 Oct 2019 00:03:34 +0900 Subject: [PATCH 13/22] Updated readme to include isHSL. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c8d960d38..faf82a80b 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ Validator | Description **isHexadecimal(str)** | check if the string is a hexadecimal number. **isHexColor(str)** | check if the string is a hexadecimal color. **isRgbColor(str, [, includePercentValues])** | check if the string is a rgb or rgba color.

`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false. +**isHSL(str)** | check if the string is an HSL (hue, saturation, lightness) color. **isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'zh-TW', 'he-IL']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIn(str, values)** | check if the string is in a array of allowed values. **isInt(str [, options])** | check if the string is an integer.

`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4). From e72967b563cd409d2a49e03a4e62db1ca82353c4 Mon Sep 17 00:00:00 2001 From: Christopher Ayala Date: Fri, 27 Dec 2019 22:32:47 +0900 Subject: [PATCH 14/22] WIP on validating degree values beyond [0,360] --- src/lib/isHSL.js | 2 +- test/validators.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 197f5422f..2a7fe7542 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,6 +1,6 @@ import assertString from './util/assertString'; -const hsl = /^(hsl)\(\s*0*([0-2]?[0-9]?[0-9]|3[0-5][0-9]|360)\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*\)$/i; +const hsl = /^(hsl)\(\s*(\+|\-)?0*[0-9]+\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*\)$/i; export default function isHSL(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index 5c8832ea0..b8d8f80bf 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3136,14 +3136,19 @@ describe('Validators', () => { 'hsL(0, 0%, 0%)', 'hSl( 360 , 100% , 100% )', 'Hsl( 00150 , 000099% , 01% )', + 'hsl(01080, 03%, 4%)', + 'hsl(-540, 03%, 4%)', + 'hsl(540, 03%, 4%)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', - 'hsl(361, 100%, 100%)', 'hsl(0260, 101%, 100%)', 'hsl(0160, 100%, 101%)', 'hsl(0160, -100%, 101%)', - 'hsl(-0160, 100%, 101%)', + 'hsl(-0160, 100$, 100%)', + 'hsl(-0160, 100%, 100a)', + 'hsl(-0160, 1000%, 101%)', + 'hsl(-0160, 100%, -101%)', ], }); }); From 395a28ed47c9a66a445f57693cc1975b149b3455 Mon Sep 17 00:00:00 2001 From: Christopher Ayala Date: Fri, 27 Dec 2019 22:43:30 +0900 Subject: [PATCH 15/22] Added + sign test case --- test/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index b8d8f80bf..6dee1781d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3138,7 +3138,7 @@ describe('Validators', () => { 'Hsl( 00150 , 000099% , 01% )', 'hsl(01080, 03%, 4%)', 'hsl(-540, 03%, 4%)', - 'hsl(540, 03%, 4%)', + 'hsl(+540, 03%, 4%)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', From c9b6a98a33aab5bbcbe73338625a17f1afe081f1 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sat, 22 Feb 2020 21:43:33 +0900 Subject: [PATCH 16/22] More comprehensive HSL check WIP --- src/lib/isHSL.js | 6 ++++-- test/validators.js | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 2a7fe7542..0f0381b0d 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,8 +1,10 @@ import assertString from './util/assertString'; -const hsl = /^(hsl)\(\s*(\+|\-)?0*[0-9]+\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*,\s*0*(0?[0-9]?[0-9]|100)%\s*\)$/i; + +const hslcomma = /^(hsl)a?\(\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?(deg|grad|rad|turn)?)\s*,\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*,\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*(,\s*(((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%?)\s*)?\)$/i; +const hslspace = /^(hsl)a?\(\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?(deg|grad|rad|turn)?)\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*\/\s*((((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%?)\s*)?\)$/i; export default function isHSL(str) { assertString(str); - return hsl.test(str); + return hslcomma.test(str) || hslspace.test(str); } diff --git a/test/validators.js b/test/validators.js index 6dee1781d..4412f9e72 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3139,6 +3139,7 @@ describe('Validators', () => { 'hsl(01080, 03%, 4%)', 'hsl(-540, 03%, 4%)', 'hsl(+540, 03%, 4%)', + 'hsl(+540, 03%, 4%, 500)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', From e873c8da7c04b48b912477a58470f5b21d67cc03 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sun, 23 Feb 2020 00:08:51 +0900 Subject: [PATCH 17/22] WIP, new tests are needed. --- src/lib/isHSL.js | 4 ++-- test/validators.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 0f0381b0d..8142ffb82 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,8 +1,8 @@ import assertString from './util/assertString'; -const hslcomma = /^(hsl)a?\(\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?(deg|grad|rad|turn)?)\s*,\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*,\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*(,\s*(((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%?)\s*)?\)$/i; -const hslspace = /^(hsl)a?\(\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?(deg|grad|rad|turn)?)\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%\s*\/\s*((((\+|\-)?0*[0-9]+(\.[0-9]+)?(e(\+|\-)?0*[0-9]+)?)%?)\s*)?\)$/i; +const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; export default function isHSL(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index 4412f9e72..7155f0ea9 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3140,6 +3140,17 @@ describe('Validators', () => { 'hsl(-540, 03%, 4%)', 'hsl(+540, 03%, 4%)', 'hsl(+540, 03%, 4%, 500)', + 'hsl(+540deg, 03%, 4%, 500)', + 'hsl(+540gRaD, 03%, 4%, 500)', + 'hsl(+540.01e-98rad, 03%, 4%, 500)', + 'hsl(-540.5turn, 03%, 4%, 500)', + 'hsl(+540, 03%, 4%, 500e-01)', + 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(200grad+.1%62%/1)', + 'hsl(200grad +.1% 62% / 1)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', From 2c954986dbf7655c6bf7b37c60928f43a9b8878a Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sun, 23 Feb 2020 00:13:45 +0900 Subject: [PATCH 18/22] Added ezkemboi test cases --- test/validators.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/validators.js b/test/validators.js index 7155f0ea9..f764fe4af 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3146,9 +3146,10 @@ describe('Validators', () => { 'hsl(-540.5turn, 03%, 4%, 500)', 'hsl(+540, 03%, 4%, 500e-01)', 'hsl(+540, 03%, 4%, 500e+80)', - 'hsl(+540, 03%, 4%, 500e+80)', - 'hsl(+540, 03%, 4%, 500e+80)', - 'hsl(+540, 03%, 4%, 500e+80)', + 'hsl(4.71239rad, 60%, 70%)', + 'hsl(270deg, 60%, 70%)', + 'hsl(270 60% 70%)', + 'hsl(.75turn, 60%, 70%)', 'hsl(200grad+.1%62%/1)', 'hsl(200grad +.1% 62% / 1)', ], From b5e1e9d9fccd99cf70c5e662f8c4acb4da147d0c Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sun, 23 Feb 2020 00:23:56 +0900 Subject: [PATCH 19/22] Added ezkemboi test cases --- src/lib/isHSL.js | 4 ++-- test/validators.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 8142ffb82..0b5ff3bc0 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -1,8 +1,8 @@ import assertString from './util/assertString'; -const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; -const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; export default function isHSL(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index f764fe4af..12b2c1fa0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3152,6 +3152,7 @@ describe('Validators', () => { 'hsl(.75turn, 60%, 70%)', 'hsl(200grad+.1%62%/1)', 'hsl(200grad +.1% 62% / 1)', + 'hsl(200+.1%62%/1)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', From e12af35ec2bff517b59a401f50f94e64b47a7b55 Mon Sep 17 00:00:00 2001 From: Christopher AYALA Date: Sun, 23 Feb 2020 01:38:01 +0900 Subject: [PATCH 20/22] Added ezkemboi test cases --- src/lib/isHSL.js | 2 +- test/validators.js | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/lib/isHSL.js b/src/lib/isHSL.js index 0b5ff3bc0..b4f446334 100644 --- a/src/lib/isHSL.js +++ b/src/lib/isHSL.js @@ -2,7 +2,7 @@ import assertString from './util/assertString'; const hslcomma = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*,\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(,\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; -const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s*)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; +const hslspace = /^(hsl)a?\(\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn|\s)(\s*(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s*(\/\s*((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s*)?\)$/i; export default function isHSL(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index 12b2c1fa0..d87a1889e 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3138,8 +3138,8 @@ describe('Validators', () => { 'Hsl( 00150 , 000099% , 01% )', 'hsl(01080, 03%, 4%)', 'hsl(-540, 03%, 4%)', - 'hsl(+540, 03%, 4%)', - 'hsl(+540, 03%, 4%, 500)', + 'hsla(+540, 03%, 4%)', + 'hsla(+540, 03%, 4%, 500)', 'hsl(+540deg, 03%, 4%, 500)', 'hsl(+540gRaD, 03%, 4%, 500)', 'hsl(+540.01e-98rad, 03%, 4%, 500)', @@ -3148,21 +3148,28 @@ describe('Validators', () => { 'hsl(+540, 03%, 4%, 500e+80)', 'hsl(4.71239rad, 60%, 70%)', 'hsl(270deg, 60%, 70%)', + 'hsl(200, +.1%, 62%, 1)', 'hsl(270 60% 70%)', + 'hsl(200, +.1e-9%, 62e10%, 1)', 'hsl(.75turn, 60%, 70%)', - 'hsl(200grad+.1%62%/1)', + // 'hsl(200grad+.1%62%/1)', //supposed to pass, but need to handle delimiters 'hsl(200grad +.1% 62% / 1)', - 'hsl(200+.1%62%/1)', + 'hsl(270, 60%, 50%, .15)', + 'hsl(270, 60%, 50%, 15%)', + 'hsl(270 60% 50% / .15)', + 'hsl(270 60% 50% / 15%)', ], invalid: [ 'hsl (360,0000000000100%,000000100%)', - 'hsl(0260, 101%, 100%)', - 'hsl(0160, 100%, 101%)', - 'hsl(0160, -100%, 101%)', - 'hsl(-0160, 100$, 100%)', + 'hsl(0260, 100 %, 100%)', + 'hsl(0160, 100%, 100%, 100 %)', 'hsl(-0160, 100%, 100a)', - 'hsl(-0160, 1000%, 101%)', - 'hsl(-0160, 100%, -101%)', + 'hsl(-0160, 100%, 100)', + 'hsl(-0160 100%, 100%, )', + 'hsl(270 deg, 60%, 70%)', + 'hsl( deg, 60%, 70%)', + 'hsl(, 60%, 70%)', + 'hsl(3000deg, 70%)', ], }); }); From cd0ec4e1f01573c6946b8d27cddc6c26a085d5a5 Mon Sep 17 00:00:00 2001 From: Christopher Ayala Date: Sun, 23 Feb 2020 14:49:12 +0900 Subject: [PATCH 21/22] Updated description of isHSL in readme. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index faf82a80b..f79ff11d7 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Validator | Description **isHexadecimal(str)** | check if the string is a hexadecimal number. **isHexColor(str)** | check if the string is a hexadecimal color. **isRgbColor(str, [, includePercentValues])** | check if the string is a rgb or rgba color.

`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false. -**isHSL(str)** | check if the string is an HSL (hue, saturation, lightness) color. +**isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). **isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'zh-TW', 'he-IL']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIn(str, values)** | check if the string is in a array of allowed values. **isInt(str [, options])** | check if the string is an integer.

`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4). @@ -188,8 +188,8 @@ In general, we follow the "fork-and-pull" Git workflow. 2. Clone the project to your own machine 3. Work on your fork 1. Make your changes and additions - - Most of your changes should be focused on `src/` and `test/` folders and/or `README.md`. - - Files such as `validator.js`, `validator.min.js` and files in `lib/` folder are autogenerated when running tests (`npm test`) and need not to be changed **manually**. + - Most of your changes should be focused on `src/` and `test/` folders and/or `README.md`. + - Files such as `validator.js`, `validator.min.js` and files in `lib/` folder are autogenerated when running tests (`npm test`) and need not to be changed **manually**. 2. Change or add tests if needed 3. Run tests and make sure they pass 4. Add changes to README.md if needed From 8d7c7a8a2f2a0f4cb106fde6599e03aa8cf253ec Mon Sep 17 00:00:00 2001 From: Christopher Ayala Date: Sun, 23 Feb 2020 15:20:44 +0900 Subject: [PATCH 22/22] Fixed readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 862b8cbc1..c5d18a663 100644 --- a/README.md +++ b/README.md @@ -110,9 +110,8 @@ Validator | Description **isHash(str, algorithm)** | check if the string is a hash of type algorithm.

Algorithm is one of `['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']` **isHexadecimal(str)** | check if the string is a hexadecimal number. **isHexColor(str)** | check if the string is a hexadecimal color. -**isHSL(str)** | check if the string is an HSL (hue, saturation, lightness) color. -**isRgbColor(str, [, includePercentValues])** | check if the string is a rgb or rgba color.

`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false. **isHSL(str)** | check if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).

Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: `hsl(200grad+.1%62%/1)`). +**isRgbColor(str, [, includePercentValues])** | check if the string is a rgb or rgba color.

`includePercentValues` defaults to `true`. If you don't want to allow to set `rgb` or `rgba` values with percents, like `rgb(5%,5%,5%)`, or `rgba(90%,90%,90%,.3)`, then set it to false. **isIdentityCard(str [, locale])** | check if the string is a valid identity card code.

`locale` is one of `['ES', 'zh-TW', 'he-IL']` OR `'any'`. If 'any' is used, function will check if any of the locals match.

Defaults to 'any'. **isIn(str, values)** | check if the string is in a array of allowed values. **isInt(str [, options])** | check if the string is an integer.

`options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4).