Skip to content

Commit b87b2ea

Browse files
committed
Added example docs
1 parent a045d8c commit b87b2ea

File tree

6 files changed

+169
-40
lines changed

6 files changed

+169
-40
lines changed

Source/HSL/CMYK.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ function toHSL (
5858
* console.debug(hsl) // [ 120 , 100 , 50 , 69 ]
5959
* ```
6060
*
61-
* @param channels [ Cyan , Magenta , Yellow , Key , ( Alpha ) ]
62-
* @returns [ Hue , Saturation , Lightness , ( Alpha ) ]
61+
* @param cmyk [ 𝗖𝘆𝗮𝗻 0 - 100 , 𝗠𝗮𝗴𝗲𝗻𝘁𝗮 0 - 100 , 𝗬𝗲𝗹𝗹𝗼𝘄 0 - 100 , 𝗞𝗲𝘆 0 - 100 , ( 𝗔𝗹𝗽𝗵𝗮 0 - 255 ) ]
62+
*
63+
* @returns [ Hue 0 - 360 , Saturation 0 - 100 , Lightness 0 - 100 , ( Alpha 0 - 255 ) ]
6364
*/
6465

6566
function cmykToHSL (

Source/HSL/Hex.ts

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,33 @@ import { rgbToHSL } from './RGB.ts'
77

88

99
/**
10-
* Parses hex color codes into their respective HSL(A) channels.
10+
* Parses a hex RGB(A) color code into a HSL(A) array.
1111
*
12-
* @param hex Hex HSL(A) color code string.
13-
* @returns Channels [ Hue , Saturation , Lightness , ( Alpha ) ] each ( 0 - 255 )
12+
* ### Examples
1413
*
15-
* Check {@link hexToRGB} for examples
14+
* Parsing a long form RGBA hex code with alpha:
15+
*
16+
* ```typescript
17+
* const hex = '#FF000069' // Red
18+
*
19+
* const hsl = hexToHSL(hex)
20+
*
21+
* console.debug(hsl) // [ 0 , 100 , 50 , 69 ]
22+
* ```
23+
*
24+
* Parsing a short form RGB hex code without #:
25+
*
26+
* ```typescript
27+
* const hex = 'F00' // Red
28+
*
29+
* const hsl = hexToHSL(hex)
30+
*
31+
* console.debug(hsl) // [ 0 , 100 , 50 ]
32+
* ```
33+
*
34+
* @param hex Hex RGB(A) color code string.
35+
*
36+
* @returns [ Hue 0 - 360 , Saturation 0 - 100 , Lightness 0 - 100 ]
1637
*/
1738

1839
function hexToHSL (
@@ -23,12 +44,45 @@ function hexToHSL (
2344

2445

2546
/**
26-
* Attempts to parse a string with a hex color code into its respective HSL(A) channels.
47+
* Attempts to parse a string as a RGB(A) hex color code into a HSL(A) array.
48+
*
49+
* ### Examples
50+
*
51+
* Parsing a long form RGBA hex code with alpha:
52+
*
53+
* ```typescript
54+
* const hex = '#FF000069' // Red
55+
*
56+
* const hsl = parseHexToHSL(hex)
57+
*
58+
* console.debug(hsl) // [ 0 , 100 , 50 , 69 ]
59+
* ```
60+
*
61+
* Parsing a short form RGB hex code without #:
62+
*
63+
* ```typescript
64+
* const hex = 'F00' // Red
65+
*
66+
* const hsl = parseHexToHSL(hex)
67+
*
68+
* console.debug(hsl) // [ 0 , 100 , 50 ]
69+
* ```
70+
*
71+
* Parsing an invalid hex color code:
72+
*
73+
* ```typescript
74+
* const hex = 'Invalid'
75+
*
76+
* const hsl = parseHexToHSL(hex)
77+
*
78+
* console.debug(hsl) // null
79+
* ```
80+
*
81+
* @param hex String possibly containing a hex RGB(A) color code.
2782
*
28-
* @param hex String possibly containing a hex HSL(A) color code.
29-
* @returns null if not found, otherwise Channels [ Hue , Saturation , Lightness , ( Alpha ) ] each ( 0 - 255 )
83+
* @returns [ Hue 0 - 360 , Saturation 0 - 100 , Lightness 0 - 100 , ( Alpha 0 - 255 ) ]
3084
*
31-
* Check {@link hexToRGB} for examples
85+
* Returns null if no color code could be matched.
3286
*/
3387

3488
function parseHexToHSL (

Source/HSL/RGB.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,31 @@ function toHSL (
8888
/**
8989
* Converts RGB(A) color arrays to HSL(A) color arrays.
9090
*
91-
* @param channels [ Red , Green , Blue , ( Alpha ) ]
92-
* @returns [ Hue , Saturation , Lightness , ( Alpha ) ]
91+
* ### Examples
92+
*
93+
* Conversion without alpha channel:
94+
*
95+
* ```typescript
96+
* const rgb = [ 255 , 0 , 0 ] // Red
97+
*
98+
* const hsl = rgbToHSL(rgb)
99+
*
100+
* console.debug(hsl) // [ 0 , 100 , 50 ]
101+
* ```
102+
*
103+
* Conversion with alpha channel:
104+
*
105+
* ```typescript
106+
* const rgba = [ 255 , 0 , 0 , 69 ] // Green
107+
*
108+
* const hsl = rgbToHSL(rgba)
109+
*
110+
* console.debug(hsl) // [ 120 , 100 , 50 , 69 ]
111+
* ```
112+
*
113+
* @param channels [ Red 0 - 255 , Green 0 - 255 , Blue 0 - 255 , ( Alpha 0 - 255 ) ]
114+
*
115+
* @returns [ Hue 0 - 360 , Saturation 0 - 100 , Lightness 0 - 100 , ( Alpha 0 - 255 ) ]
93116
*/
94117

95118
function rgbToHSL (

Source/RGB/HSL.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,34 @@ function toRGB (
6969
}
7070

7171

72-
/*
73-
* [ H , S , L , (A) ] -> [ R , G , B , (A) ]
72+
/**
73+
* Converts a HSL(A) color array to a RGB(A) color array.
74+
*
75+
* ### Examples
76+
*
77+
* Conversion without alpha channel:
78+
*
79+
* ```typescript
80+
* const hsl = [ 0 , 100 , 50 ] // Red
81+
*
82+
* const rgb = hslToRGB(hsl)
83+
*
84+
* console.debug(rgb) // [ 255 , 0 , 0 ]
85+
* ```
86+
*
87+
* Conversion with alpha channel:
88+
*
89+
* ```typescript
90+
* const hsl = [ 0 , 100 , 50 , 69 ] // Green
91+
*
92+
* const rgb = hslToRGB(hsl)
93+
*
94+
* console.debug(rgb) // [ 255 , 0 , 0 , 69 ]
95+
* ```
96+
*
97+
* @param channels [ Hue 0 - 360 , Saturation 0 - 100 , Lightness 0 - 100 , ( Alpha 0 - 255 ) ]
98+
*
99+
* @returns [ Red 0 - 255 , Green 0 - 255 , Blue 0 - 255 , ( Alpha 0 - 255 ) ]
74100
*/
75101

76102
function hslToRGB (

Source/RGB/Hex.ts

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,33 @@ function matchChannels ( hex : string ){
4040

4141

4242
/**
43-
* Parses hex color codes into their respective RGB(A) channels.
43+
* Parses a hex RGB(A) color code into a RGB(A) array.
4444
*
45-
* @param hex Hex RGB(A) color code string.
46-
* @returns Channels [ Red , Green , Blue , ( Alpha ) ] each ( 0 - 255 )
45+
* ### Examples
4746
*
47+
* Parsing a long form RGBA hex code with alpha:
4848
*
49-
* ## Examples
49+
* ```typescript
50+
* const hex = '#FF000069' // Red
5051
*
51-
* Long form RGBA color codes:
52+
* const rgb = hexToRGB(hex)
5253
*
53-
* ```typescript
54-
* hexToRGB('#AABBCCDD')
55-
* hexToRGB('AABBCCDD')
54+
* console.debug(rgb) // [ 255 , 0 , 0 , 69 ]
5655
* ```
5756
*
58-
* Long form RGB color codes:
57+
* Parsing a short form RGB hex code without #:
5958
*
6059
* ```typescript
61-
* hexToRGB('#AABBCC')
62-
* hexToRGB('AABBCC')
63-
* ```
60+
* const hex = 'F00' // Red
6461
*
65-
* Short form RGBA color codes:
62+
* const rgb = hexToRGB(hex)
6663
*
67-
* ```typescript
68-
* hexToRGB('#ABCD')
69-
* hexToRGB('ABCD')
64+
* console.debug(rgb) // [ 255 , 0 , 0 ]
7065
* ```
7166
*
72-
* Short form RGB color codes:
67+
* @param hex Hex RGB(A) color code string.
7368
*
74-
* ```typescript
75-
* hexToRGB('#ABC')
76-
* hexToRGB('ABC')
77-
* ```
69+
* @returns [ Hue 0 - 360 , Saturation 0 - 100 , Lightness 0 - 100 ]
7870
*/
7971

8072
function hexToRGB (
@@ -85,12 +77,45 @@ function hexToRGB (
8577

8678

8779
/**
88-
* Attempts to parse a string with a hex color code into its respective RGB(A) channels.
80+
* Attempts to parse a string as a RGB(A) hex color code into a RGB(A) array.
81+
*
82+
* ### Examples
83+
*
84+
* Parsing a long form RGBA hex code with alpha:
85+
*
86+
* ```typescript
87+
* const hex = '#FF000069' // Red
88+
*
89+
* const rgb = parseHexToRGB(hex)
90+
*
91+
* console.debug(rgb) // [ 255 , 0 , 0 , 69 ]
92+
* ```
93+
*
94+
* Parsing a short form RGB hex code without #:
95+
*
96+
* ```typescript
97+
* const hex = 'F00' // Red
98+
*
99+
* const rgb = parseHexToRGB(hex)
100+
*
101+
* console.debug(rgb) // [ 255 , 0 , 0 ]
102+
* ```
103+
*
104+
* Parsing an invalid hex color code:
105+
*
106+
* ```typescript
107+
* const hex = 'Invalid'
108+
*
109+
* const rgb = parseHexToRGB(hex)
110+
*
111+
* console.debug(rgb) // null
112+
* ```
113+
*
114+
* @param hex Hex RGB(A) color code string.
89115
*
90-
* @param hex String possibly containing a hex RGB(A) color code.
91-
* @returns null if not found, otherwise Channels [ Red , Green , Blue , ( Alpha ) ] each ( 0 - 255 )
116+
* @returns [ Hue 0 - 360 , Saturation 0 - 100 , Lightness 0 - 100 , ( Alpha 0 - 255 ) ]
92117
*
93-
* Check {@link hexToRGB} for examples
118+
* Returns null if no color code could be matched.
94119
*/
95120

96121
function parseHexToRGB (

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
"name" : "@omega/color" ,
13-
"version" : "1.2.6" ,
13+
"version" : "1.2.7" ,
1414

1515
"exports" : {
1616
"./HSL" : "./Source/HSL/mod.ts" ,

0 commit comments

Comments
 (0)