From cb251407947337ea5601e241233d6dedd6535e47 Mon Sep 17 00:00:00 2001 From: Stefan Fejes Date: Fri, 30 Oct 2020 16:38:31 +0100 Subject: [PATCH] make ligten -> changeLightness --- snippets/{lighten.md => changeLightness.md} | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) rename snippets/{lighten.md => changeLightness.md} (58%) diff --git a/snippets/lighten.md b/snippets/changeLightness.md similarity index 58% rename from snippets/lighten.md rename to snippets/changeLightness.md index 327a5a891..40e343602 100644 --- a/snippets/lighten.md +++ b/snippets/changeLightness.md @@ -1,9 +1,9 @@ --- -title: lighten +title: changeLightness tags: string,browser,regexp,beginner --- -Returns the string value for the lightened color in `hsl` format. +Returns the string value of the color with changed lightness in `hsl` format. - Use `String.prototype.match()` to get an array of 3 string with the numeric values. - Use `Array.prototype.map()` in combination with `Number` to convert them into an array of numeric values. @@ -11,12 +11,12 @@ Returns the string value for the lightened color in `hsl` format. - Form a valid `hsl` color string. ```js -const lighten = (amount, hslStr) => { +const changeLightness = (delta, hslStr) => { const [hue, saturation, lightness] = hslStr.match(/\d+/g).map(Number); const newLightness = Math.max( 0, - Math.min(100, lightness + parseFloat(amount)) + Math.min(100, lightness + parseFloat(delta)) ); return `hsl(${hue}, ${saturation}%, ${newLightness}%)`; @@ -24,5 +24,6 @@ const lighten = (amount, hslStr) => { ``` ```js -lighten(10, "hsl(330, 50%, 50%)"); // 'hsl(330, 50%, 60%)' +changeLightness(10, "hsl(330, 50%, 50%)"); // 'hsl(330, 50%, 60%)' - lightens the color by 10% +changeLightness(-10, "hsl(330, 50%, 50%)"); // 'hsl(330, 50%, 40%)' - darkens the color by 10% ```