UNPKG

1.36 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = hsl;
5var _hslToHex = _interopRequireDefault(require("../internalHelpers/_hslToHex"));
6var _errors = _interopRequireDefault(require("../internalHelpers/_errors"));
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8/**
9 * Returns a string value for the color. The returned result is the smallest possible hex notation.
10 *
11 * @example
12 * // Styles as object usage
13 * const styles = {
14 * background: hsl(359, 0.75, 0.4),
15 * background: hsl({ hue: 360, saturation: 0.75, lightness: 0.4 }),
16 * }
17 *
18 * // styled-components usage
19 * const div = styled.div`
20 * background: ${hsl(359, 0.75, 0.4)};
21 * background: ${hsl({ hue: 360, saturation: 0.75, lightness: 0.4 })};
22 * `
23 *
24 * // CSS in JS Output
25 *
26 * element {
27 * background: "#b3191c";
28 * background: "#b3191c";
29 * }
30 */
31function hsl(value, saturation, lightness) {
32 if (typeof value === 'number' && typeof saturation === 'number' && typeof lightness === 'number') {
33 return (0, _hslToHex["default"])(value, saturation, lightness);
34 } else if (typeof value === 'object' && saturation === undefined && lightness === undefined) {
35 return (0, _hslToHex["default"])(value.hue, value.saturation, value.lightness);
36 }
37 throw new _errors["default"](1);
38}
39module.exports = exports.default;
\No newline at end of file