UNPKG

@chayns/colors

Version:

JavaScript utility functions for the calculation of colors for chayns

36 lines (35 loc) 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = hexToRgb255; var _constants = require("../../utils/constants"); var _is = require("../../utils/is"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function hexToRgb255(hex) { if (!(0, _is.isHex)(hex)) { return null; } var components = hex.match(_constants.HEX_REGEX); if (!(components !== null && components !== void 0 && components[1])) { return null; } var retObj = { r: parseInt(components[1].substring(0, 2), 16), g: parseInt(components[1].substring(2, 4), 16), b: parseInt(components[1].substring(4, 6), 16) }; var a = parseInt(components[1].substring(6, 8), 16) / 255; if ((0, _is.isNumber)(a)) { return _objectSpread(_objectSpread({}, retObj), {}, { a: a }); } return retObj; } //# sourceMappingURL=hexToRgb255.js.map