Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit 7c35b1b

Browse files
committed
Added alpha channel testing
1 parent fe66f93 commit 7c35b1b

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

Source/Sources/HSL.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11

22
const { min , max , round } = Math;
33

4-
54
const offsets = [ 0 , 8 , 4 ];
65

76

87
function toRGB([ Hue , Saturation , Lightness ]){
98

9+
// [ 0 - 100 ] -> [ 0 - 1 ]
10+
1011
Saturation *= 0.01;
1112
Lightness *= 0.01;
1213

@@ -16,7 +17,11 @@ function toRGB([ Hue , Saturation , Lightness ]){
1617

1718
const a = Saturation * min(Lightness,1 - Lightness);
1819

19-
return offsets.map((offset) => {
20+
return offsets
21+
.map(toChannel);
22+
23+
24+
function toChannel ( offset ){
2025

2126
offset += Hue;
2227

@@ -47,7 +52,7 @@ function toRGB([ Hue , Saturation , Lightness ]){
4752
// To Int
4853

4954
return round(offset);
50-
});
55+
}
5156
}
5257

5358

@@ -56,13 +61,6 @@ function toRGB([ Hue , Saturation , Lightness ]){
5661
*/
5762

5863
export default function fromHSL ( colors ){
59-
60-
const rgb = toRGB(colors);
61-
62-
const alpha = colors[3];
63-
64-
if(alpha)
65-
rgb.push(alpha);
66-
67-
return rgb;
64+
return toRGB(colors)
65+
.concat(colors.splice(3,1));
6866
}

Tests/HSL.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
import { assertHSLIsRGB } from 'AssertColor'
33

44

5-
Deno.test('HSL Array Conversion',() => {
5+
Deno.test('HSL array conversion retains alpha',() => {
6+
7+
assertHSLIsRGB([ 0 , 0 , 0 , 64 ],[ 0 , 0 , 0 , 64 ]);
8+
9+
})
10+
11+
12+
Deno.test('HSL array conversion works',() => {
613

714
// Black
815

Tests/Hex.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
import { assertHexIsRGB } from 'AssertColor'
33

44

5+
Deno.test('Hex string conversion retains alpha',() => {
6+
7+
assertHexIsRGB('#00000040',[ 0 , 0 , 0 , 64 ]);
8+
9+
})
10+
11+
512
Deno.test('Hex String Conversion',() => {
613

714
// Black
@@ -33,6 +40,6 @@ Deno.test('Hex String Conversion',() => {
3340

3441
assertHexIsRGB('',null);
3542
assertHexIsRGB('#XXXXXX',null);
36-
assertHexIsRGB('#000000XX',null);
43+
assertHexIsRGB('#00000000XX',null);
3744

3845
})

0 commit comments

Comments
 (0)