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:
Amruth Pillai
2026-07-04 20:53:51 +02:00
parent 5226f04e86
commit a5935dee0f
7 changed files with 70 additions and 86 deletions
-1
View File
@@ -45,7 +45,6 @@
"@reactive-resume/utils": "workspace:*",
"@sindresorhus/slugify": "^3.0.0",
"@t3-oss/env-core": "^0.13.11",
"@uiw/color-convert": "^2.10.3",
"ai": "^7.0.15",
"bcrypt": "^6.0.0",
"better-auth": "1.6.23",
-1
View File
@@ -28,7 +28,6 @@
"@orpc/experimental-ratelimit",
"@sindresorhus/slugify",
"@t3-oss/env-core",
"@uiw/color-convert",
"ai",
"bcrypt",
"cjk-regex",
-1
View File
@@ -27,7 +27,6 @@
},
"dependencies": {
"@sindresorhus/slugify": "^3.0.0",
"@uiw/color-convert": "^2.10.3",
"clsx": "^2.1.1",
"tailwind-merge": "^3.6.0",
"unique-names-generator": "^4.7.1",
+4 -6
View File
@@ -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
+9 -15
View File
@@ -1,17 +1,11 @@
const MONTH_NAMES = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
// ponytail: Intl replaces the 12-line MONTH_NAMES array; pinned to en-US so output is stable
const fmt = new Intl.DateTimeFormat("en-US", { month: "long" });
function getMonthName(month: string | undefined): string {
const index = Number.parseInt(month ?? "1", 10) - 1;
if (index < 0 || index > 11) return "undefined";
return fmt.format(new Date(2000, index, 1));
}
/**
* Formats a partial ISO 8601 date string (YYYY, YYYY-MM, or YYYY-MM-DD)
@@ -22,7 +16,7 @@ export function formatDate(date: string, includeDay = false): string {
if (parts.length >= 2) {
const [year, month] = parts;
const monthName = MONTH_NAMES[Number.parseInt(month ?? "1", 10) - 1];
const monthName = getMonthName(month);
if (parts.length === 3 && includeDay) {
return `${monthName} ${parts[2]}, ${year}`;
+57 -56
View File
@@ -1,61 +1,62 @@
import z from "zod";
export const localeSchema = z.union([
z.literal("af-ZA"),
z.literal("am-ET"),
z.literal("ar-SA"),
z.literal("az-AZ"),
z.literal("bg-BG"),
z.literal("bn-BD"),
z.literal("ca-ES"),
z.literal("cs-CZ"),
z.literal("da-DK"),
z.literal("de-DE"),
z.literal("el-GR"),
z.literal("en-US"),
z.literal("en-GB"),
z.literal("es-ES"),
z.literal("fa-IR"),
z.literal("fi-FI"),
z.literal("fr-FR"),
z.literal("he-IL"),
z.literal("hi-IN"),
z.literal("hu-HU"),
z.literal("id-ID"),
z.literal("it-IT"),
z.literal("ja-JP"),
z.literal("km-KH"),
z.literal("kn-IN"),
z.literal("ko-KR"),
z.literal("lt-LT"),
z.literal("lv-LV"),
z.literal("ml-IN"),
z.literal("mr-IN"),
z.literal("ms-MY"),
z.literal("ne-NP"),
z.literal("nl-NL"),
z.literal("no-NO"),
z.literal("or-IN"),
z.literal("pl-PL"),
z.literal("pt-BR"),
z.literal("pt-PT"),
z.literal("ro-RO"),
z.literal("ru-RU"),
z.literal("sk-SK"),
z.literal("sl-SI"),
z.literal("sq-AL"),
z.literal("sr-SP"),
z.literal("sv-SE"),
z.literal("ta-IN"),
z.literal("te-IN"),
z.literal("th-TH"),
z.literal("tr-TR"),
z.literal("uk-UA"),
z.literal("uz-UZ"),
z.literal("vi-VN"),
z.literal("zh-CN"),
z.literal("zh-TW"),
z.literal("zu-ZA"),
// ponytail: z.enum([...]) over 56 z.literal calls; same parse behavior, same inferred union type
export const localeSchema = z.enum([
"af-ZA",
"am-ET",
"ar-SA",
"az-AZ",
"bg-BG",
"bn-BD",
"ca-ES",
"cs-CZ",
"da-DK",
"de-DE",
"el-GR",
"en-US",
"en-GB",
"es-ES",
"fa-IR",
"fi-FI",
"fr-FR",
"he-IL",
"hi-IN",
"hu-HU",
"id-ID",
"it-IT",
"ja-JP",
"km-KH",
"kn-IN",
"ko-KR",
"lt-LT",
"lv-LV",
"ml-IN",
"mr-IN",
"ms-MY",
"ne-NP",
"nl-NL",
"no-NO",
"or-IN",
"pl-PL",
"pt-BR",
"pt-PT",
"ro-RO",
"ru-RU",
"sk-SK",
"sl-SI",
"sq-AL",
"sr-SP",
"sv-SE",
"ta-IN",
"te-IN",
"th-TH",
"tr-TR",
"uk-UA",
"uz-UZ",
"vi-VN",
"zh-CN",
"zh-TW",
"zu-ZA",
]);
export type Locale = z.infer<typeof localeSchema>;
-6
View File
@@ -165,9 +165,6 @@ importers:
'@t3-oss/env-core':
specifier: ^0.13.11
version: 0.13.11(typescript@6.0.3)(zod@4.4.3)
'@uiw/color-convert':
specifier: ^2.10.3
version: 2.10.3(@babel/runtime@7.29.7)
ai:
specifier: ^7.0.15
version: 7.0.15(zod@4.4.3)
@@ -1092,9 +1089,6 @@ importers:
'@sindresorhus/slugify':
specifier: ^3.0.0
version: 3.0.0
'@uiw/color-convert':
specifier: ^2.10.3
version: 2.10.3(@babel/runtime@7.29.7)
clsx:
specifier: ^2.1.1
version: 2.1.1