Because the parseToHsl can return a "long" float decimal, using it as a literal string can generate error.
The code below is in a bug reproduction logic, because the lib allow to use the hsl as an object (HslColor | HslColor types).
Additional context
But my goal is to get/generate hsl props programmatically from a hex/rgb value without doing extra work like Math.round() / parseFloat() / .toFixed() since the polished lib looks to already do it for other functions/methods.
Exemple of expected result from using the parseToHsl result:
// CJS
PolishedError: An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#5 for more information.
// ESM - Node
NonErrorEmittedError: (Emitted value instead of an instance of Error) Error: Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation.
What You Expected To See
Object {red: 66, green: 0, blue: 4}
or possible parseToHsl return:
Object {hue: 356.31, saturation: 1, lightness: 0.127, alpha: 1}
// lightness property has 3 decimal to allow the conversion into `12.7%`
polished
version: 4.2.2The bug looks similar to the https://github.com/styled-components/polished/issues/610 with the
alpha
which fail from a 3-digit decimal. But this bug is about the hue/saturation/lightness values.https://github.com/styled-components/polished/blob/a6c55c8b3feb0010c63c55eb5b18cc3090050c15/src/color/parseToRgb.js#L14
Because the
parseToHsl
can return a "long" float decimal, using it as a literal string can generate error. The code below is in a bug reproduction logic, because the lib allow to use the hsl as an object (HslColor | HslColor
types).Additional context
But my goal is to get/generate
hsl
props programmatically from a hex/rgb value without doing extra work like Math.round() / parseFloat() / .toFixed() since the polished lib looks to already do it for other functions/methods.Exemple of expected result from using the
parseToHsl
result:Mixin/Helper/Shorthand Usage
What You Are Seeing
What You Expected To See
or possible
parseToHsl
return:Reproduction
Runkit example