Skip to content

Commit

Permalink
add test and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Charbonnel committed Oct 13, 2020
1 parent a45168f commit f510af0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,30 @@ r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
});
}

```

## hslaVector3

```js

import { hslaVector3 } from "@ap.cx/hues";

```

change hsl value.

```js

const result = hslaVector3({ h: 0, s: 90, l: 90, a: 1 }, [0,0,1])

console.log(result);

> { h: 0, s: 90, l: 91, a: 1 };

```

---

## color-string
Expand Down
4 changes: 2 additions & 2 deletions src/hslaVector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function hslaVector3 ({ h, s, l, a }, v3) {
h1 += 360;
}

let s1 = Math.min(s + sv, 100); // caping 100;
let l1 = Math.min(l + lv, 100); // caping 100;
let s1 = Math.min(Math.max(s + sv, 0), 100); // caping 0, 100;
let l1 = Math.min(Math.max(l + lv, 0), 100); // caping 0, 100;

return { h: h1, s: s1, l: l1, a};
}
Expand Down
12 changes: 10 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const {
contrast,
relativeLuminance,
aa,
aaa,
aaa,
hslaVector3,
} = require('..');

/* function MockHues () {
Expand Down Expand Up @@ -186,5 +187,12 @@ testRgb2hex({ r: 1, g: 1, b: 1, a: 1 }, '#ffffff');

// https://www.topster.net/relative-luminance/

function testHslaVector3(hsla, v3, expected) {
assert.deepStrictEqual(hslaVector3(hsla, v3), expected);
console.log(`\u001B[32m✓\u001B[39m hslaVector3 ${expected}`);
}


testHslaVector3({ h: 0, s: 90, l: 90, a: 1 }, [0,0,1], { h: 0, s: 90, l: 91, a: 1 });
testHslaVector3({ h: 0, s: 90, l: 90, a: 1 }, [-1,0,1], { h: 359, s: 90, l: 91, a: 1 });
testHslaVector3({ h: 0, s: 90, l: 90, a: 1 }, [0,0,100], { h: 0, s: 90, l: 100, a: 1 });
testHslaVector3({ h: 0, s: 10, l: 90, a: 1 }, [0,-11,100], { h: 0, s: 0, l: 100, a: 1 });

0 comments on commit f510af0

Please sign in to comment.