mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-24 17:03:55 +10:00
refactor(utils): replace MONTH_NAMES array, drop @uiw/color-convert, use z.enum for localeSchema
Finding 1: Replace hand-rolled MONTH_NAMES[12] array with Intl.DateTimeFormat("en-US", {month:"long"}).
Finding 2: Drop @uiw/color-convert fallback — parseColorString already rejects the same inputs, return "#000000" instead. Remove dep from utils and server package.json.
Finding 3: Replace 56 z.literal calls in z.union with z.enum([...]); identical parse behavior and inferred type.
Claude-Session: https://claude.ai/code/session_012Bnvt1MghwHj4qQRxuQUGa
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
import type { ColorResult } from "@uiw/color-convert";
|
||||
import { hsvaToHex, rgbaStringToHsva } from "@uiw/color-convert";
|
||||
type ParsedColor = { r: number; g: number; b: number; a: number };
|
||||
|
||||
export function rgbaStringToHex(rgba: string): string {
|
||||
const color = parseColorString(rgba);
|
||||
if (color) return `#${toHexComponent(color.r)}${toHexComponent(color.g)}${toHexComponent(color.b)}`;
|
||||
|
||||
const hsva = rgbaStringToHsva(rgba);
|
||||
return hsvaToHex(hsva);
|
||||
// ponytail: unrecognized format → black; same result the prior @uiw/color-convert fallback produced
|
||||
return "#000000";
|
||||
}
|
||||
|
||||
function toHexComponent(value: number): string {
|
||||
return Math.max(0, Math.min(255, value)).toString(16).padStart(2, "0");
|
||||
}
|
||||
|
||||
export function parseColorString(value: string): ColorResult["rgba"] | null {
|
||||
export function parseColorString(value: string): ParsedColor | null {
|
||||
const trimmed = value.trim();
|
||||
|
||||
// Parse rgb/rgba colors
|
||||
|
||||
Reference in New Issue
Block a user