Spot the bug - #140: Color Parser Utility

Why is my custom color parser shifting hue angles unpredictably?

function normalizeColorChannel(input) {
  const trimmed = input.trim();
  const isPercentage = trimmed.endsWith('%');
  const rawNum = parseFloat(trimmed);
  
  if (Number.isNaN(rawNum)) return 0;
  
  if (isPercentage) {
    return Math.min(100, Math.max(0, rawNum)) / 100;
  }
  return Math.min(255, Math.max(0, rawNum)) / 255;
}

function parseHslString(hslStr) {
  const parts = hslStr.replace(/hsla?\(|\)/gi, '').split(',');
  if (parts.length < 3) return null;
  
  const hue = parseFloat(parts[0]) % 360;
  const sat = normalizeColorChannel(parts[1]);
  const light = normalizeColorChannel(parts[2]);
  
  return { h: hue, s: sat, l: light };
}

Reply with what is broken and how you would fix it.