UNPKG

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