-
-
Notifications
You must be signed in to change notification settings - Fork 209
/
parseToHsl.js
24 lines (21 loc) · 903 Bytes
/
parseToHsl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// @flow
import parseToRgb from './parseToRgb'
import rgbToHsl from '../internalHelpers/_rgbToHsl'
import type { HslColor, HslaColor } from '../types/color'
/**
* Returns an HslColor or HslaColor object. This utility function is only useful
* if want to extract a color component. With the color util `toColorString` you
* can convert a HslColor or HslaColor object back to a string.
*
* @example
* // Assigns `{ red: 255, green: 0, blue: 0 }` to color1
* const color1 = 'rgb(255, 0, 0)';
* // Assigns `{ red: 92, green: 102, blue: 112, alpha: 0.75 }` to color2
* const color2 = 'hsla(210, 10%, 40%, 0.75)';
*/
function parseToHsl(color: string): HslColor | HslaColor {
// Note: At a later stage we can optimize this function as right now a hsl
// color would be parsed converted to rgb values and converted back to hsl.
return rgbToHsl(parseToRgb(color))
}
export default parseToHsl