ai made goop, ai fix goop

This commit is contained in:
kree 2026-08-15 02:07:20 -04:00
parent 090d299a84
commit 4e1f26646c

View file

@ -4,24 +4,29 @@
* This is just cause I gotta stick to not touching Public templates
*/
// keys whose Go field name can't be derived from separators alone
type Special = { id: "ID"; flatrate: "FlatRate" };
type Camel<S extends string> =
S extends "id" ? "ID" :
S extends `${infer H}.${infer T}` ? `${H}${Capitalize<Camel<T>>}` :
S extends `${infer H}_${infer T}` ? `${H}${Capitalize<Camel<T>>}` : S;
type Pascal<S extends string> = S extends "id" ? "ID" : Capitalize<Camel<S>>;
type Pascal<S extends string> =
S extends keyof Special ? Special[S] : Capitalize<Camel<S>>;
export type Camelize<T> =
T extends readonly (infer U)[] ? Camelize<U>[] :
T extends object ? { [K in keyof T as Pascal<K & string>]: Camelize<T[K]> } :
T;
const special: Record<string, string> = { id: "ID", flatrate: "FlatRate" };
const pascalKey = (k: string) =>
k === "id"
? "ID"
: k
.replace(/[._](\w)/g, (_, c) => c.toUpperCase())
.replace(/^\w/, (c) => c.toUpperCase());
special[k] ??
k
.replace(/[._](\w)/g, (_, c) => c.toUpperCase())
.replace(/^\w/, (c) => c.toUpperCase());
export default function ungoop<T>(obj: T): Camelize<T> {
return (