PageSourceSearch

https://jayreddinjr-jr-odysseus-hf.hf.space/static/js/color/hex.js

js jayreddinjr-jr-odysseus-hf.hf.space collected 2026-10-04 17:00:23 UTC 589 bytes, 14 lines download raw bytes

1// static/js/color/hex.js
2//
3// Parse a CSS hex color into {r, g, b}. Pure — no DOM — so it can be reused
4// across modules and unit-tested under node.
5
6// Accepts "#rgb", "#rrggbb" (with or without the leading '#'). Returns null
7// for anything that isn't a valid 3- or 6-digit hex color.
8export function hexToRgb(hex) {
9  let h = String(hex || '').trim().replace(/^#/, '');
10  if (h.length === 3) h = h.split('').map((c) => c + c).join('');
11  if (!/^[0-9a-fA-F]{6}$/.test(h)) return null;
12  const n = parseInt(h, 16);
13  return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 };
14}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.