From f510af0ef05d152e8369fa080d47759ebb7e16cd Mon Sep 17 00:00:00 2001 From: Thierry Charbonnel Date: Tue, 13 Oct 2020 10:28:03 -0400 Subject: [PATCH] add test and doc --- README.md | 23 ++++++++++++++++++++++- src/hslaVector3.js | 4 ++-- test/test.js | 12 ++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 03328cd..41834dd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/hslaVector3.js b/src/hslaVector3.js index 45272fa..123bff4 100644 --- a/src/hslaVector3.js +++ b/src/hslaVector3.js @@ -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}; } diff --git a/test/test.js b/test/test.js index e994fbd..41c106c 100644 --- a/test/test.js +++ b/test/test.js @@ -10,7 +10,8 @@ const { contrast, relativeLuminance, aa, - aaa, + aaa, + hslaVector3, } = require('..'); /* function MockHues () { @@ -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 });