MCPcopy Index your code
hub / github.com/nodejs/node / getHexStyle

Function getHexStyle

lib/util.js:163–177  ·  view source on GitHub ↗

* Returns the cached ANSI escape sequences for a hex color. * Computes and caches on first use to avoid repeated Buffer allocations. * @param {string} hex A valid hex color string (#RGB or #RRGGBB) * @returns {{openSeq: string, closeSeq: string}}

(hex)

Source from the content-addressed store, hash-verified

161 * @returns {{openSeq: string, closeSeq: string}}
162 */
163function getHexStyle(hex) {
164 const cache = getHexStyleCache();
165 const cached = cache.get(hex);
166 if (cached !== undefined) return cached;
167 const { 0: r, 1: g, 2: b } = hexToRgb(hex);
168 const style = {
169 __proto__: null,
170 openSeq: kEscape + rgbToAnsi24Bit(r, g, b) + kEscapeEnd,
171 closeSeq: kHexCloseSeq,
172 };
173 if (cache.size >= kHexStyleCacheMax)
174 cache.delete(cache.keys().next().value);
175 cache.set(hex, style);
176 return style;
177}
178
179function replaceCloseCode(str, closeSeq, openSeq, keepClose) {
180 const closeLen = closeSeq.length;

Callers 1

styleTextFunction · 0.85

Calls 8

getHexStyleCacheFunction · 0.85
hexToRgbFunction · 0.85
rgbToAnsi24BitFunction · 0.85
getMethod · 0.65
deleteMethod · 0.65
nextMethod · 0.65
keysMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…