UNPKG

@yookue/ts-lang-utils

Version:

Common lang utilities for typescript

52 lines (50 loc) 1.67 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/hslToHex.ts var hslToHex_exports = {}; __export(hslToHex_exports, { hslToHex: () => hslToHex }); module.exports = __toCommonJS(hslToHex_exports); function hslToHex(hsl) { if (!hsl) { return void 0; } let alias = null; if (typeof hsl === "string") { const arr = /hsl\((\d+),\s*([\d.]+),\s*([\d.]+)\)/.exec(hsl); if (!arr || arr.length !== 4) { return void 0; } alias = arr.slice(1).map(Number); } else { alias = hsl; } const [h, s, l] = alias; const a = s * Math.min(l, 1 - l); const f = (n) => { const k = (n + h / 30) % 12; const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1); return Math.round(255 * color).toString(16).padStart(2, "0"); }; return `#${f(0)}${f(8)}${f(4)}`; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { hslToHex });