Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature isHSL #1159

Merged
merged 25 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c38fdc3
isHSL WIP
ayala-io Oct 15, 2019
067f03c
Added another valid test case.
ayala-io Oct 15, 2019
6783382
Updated readme to include isHSL.
ayala-io Oct 15, 2019
be3ea74
Merge remote-tracking branch 'upstream/master' into add-feature-isHSL
ayala-io Dec 27, 2019
0a71904
WIP on validating degree values beyond [0,360]
ayala-io Dec 27, 2019
dc0b34b
Added + sign test case
ayala-io Dec 27, 2019
d2ea634
Merge remote-tracking branch 'upstream/master' into add-feature-isHSL
ayala-io Feb 22, 2020
cd611f2
More comprehensive HSL check WIP
ayala-io Feb 22, 2020
4315d00
WIP, new tests are needed.
ayala-io Feb 22, 2020
6e0b331
Added ezkemboi test cases
ayala-io Feb 22, 2020
c90164a
Added ezkemboi test cases
ayala-io Feb 22, 2020
5b5becc
Added ezkemboi test cases
ayala-io Feb 22, 2020
71966a4
isHSL WIP
ayala-io Oct 15, 2019
b7f2c19
Added another valid test case.
ayala-io Oct 15, 2019
42d4342
Updated readme to include isHSL.
ayala-io Oct 15, 2019
e72967b
WIP on validating degree values beyond [0,360]
ayala-io Dec 27, 2019
395a28e
Added + sign test case
ayala-io Dec 27, 2019
c9b6a98
More comprehensive HSL check WIP
ayala-io Feb 22, 2020
e873c8d
WIP, new tests are needed.
ayala-io Feb 22, 2020
2c95498
Added ezkemboi test cases
ayala-io Feb 22, 2020
b5e1e9d
Added ezkemboi test cases
ayala-io Feb 22, 2020
e12af35
Added ezkemboi test cases
ayala-io Feb 22, 2020
cd0ec4e
Updated description of isHSL in readme.
ayala-io Feb 23, 2020
cfcfee6
Merge remote-tracking branch 'origin/add-feature-isHSL' into add-feat…
ayala-io Feb 23, 2020
8d7c7a8
Fixed readme
ayala-io Feb 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Validator | Description
**isHash(str, algorithm)** | check if the string is a hash of type algorithm.<br/><br/>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.
ayala-io marked this conversation as resolved.
Show resolved Hide resolved
**isIdentityCard(str [, locale])** | check if the string is a valid identity card code.<br/><br/>`locale` is one of `['ES', 'zh-TW', 'he-IL']` OR `'any'`. If 'any' is used, function will check if any of the locals match.<br/><br/>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.<br/><br/>`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).
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -141,6 +142,7 @@ const validator = {
isOctal,
isDivisibleBy,
isHexColor,
isHSL,
isISRC,
isMD5,
isHash,
Expand Down
8 changes: 8 additions & 0 deletions src/lib/isHSL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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;

export default function isHSL(str) {
assertString(str);
return hsl.test(str);
}
27 changes: 27 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,33 @@ describe('Validators', () => {
});
});

it('should validate HSL color strings', () => {
test({
validator: 'isHSL',
valid: [
'hsl(360,0000000000100%,000000100%)',
'hsl(000010, 00000000001%, 00000040%)',
'HSL(00000,0000000000100%,000000100%)',
'hsL(0, 0%, 0%)',
'hSl( 360 , 100% , 100% )',
ayala-io marked this conversation as resolved.
Show resolved Hide resolved
'Hsl( 00150 , 000099% , 01% )',
'hsl(01080, 03%, 4%)',
'hsl(-540, 03%, 4%)',
'hsl(+540, 03%, 4%)',
],
invalid: [
'hsl (360,0000000000100%,000000100%)',
'hsl(0260, 101%, 100%)',
'hsl(0160, 100%, 101%)',
'hsl(0160, -100%, 101%)',
'hsl(-0160, 100$, 100%)',
'hsl(-0160, 100%, 100a)',
'hsl(-0160, 1000%, 101%)',
'hsl(-0160, 100%, -101%)',
],
});
});

it('should validate ISRC code strings', () => {
test({
validator: 'isISRC',
Expand Down