UNPKG

@yookue/ts-lang-utils

Version:

Common lang utilities for typescript

44 lines (42 loc) 1.54 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/util/ColorUtils/hexToRgb.ts var hexToRgb_exports = {}; __export(hexToRgb_exports, { hexToRgb: () => hexToRgb }); module.exports = __toCommonJS(hexToRgb_exports); function hexToRgb(hex) { if (!hex) { return void 0; } const rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; const rep = hex.replace(rgx, (m, r, g, b) => r + r + g + g + b + b); const arr = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(rep); if (!arr || arr.length !== 4) { return void 0; } const hexR = Number.parseInt(arr[1], 16); const hexG = Number.parseInt(arr[2], 16); const hexB = Number.parseInt(arr[3], 16); return `rgb(${hexR}, ${hexG}, ${hexB})`; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { hexToRgb });