33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import * as z from "zod";
|
|
|
|
export const glossaryKinds = ["character", "weapon", "artifact"] as const;
|
|
export type GlossaryKind = (typeof glossaryKinds)[number];
|
|
|
|
export const glossaryAliasInputSchema = z.strictObject({
|
|
kind: z.enum(glossaryKinds),
|
|
catalogKey: z.string().trim().min(1).max(64),
|
|
alias: z.string().trim().min(1).max(120),
|
|
});
|
|
|
|
export function normalizeGlossaryAlias(value: string): string {
|
|
return value.trim().normalize("NFKC").toLocaleLowerCase("th");
|
|
}
|
|
|
|
export function aliasesByItem(
|
|
rows: ReadonlyArray<{ kind: string; catalogKey: string; alias: string }>,
|
|
): Record<GlossaryKind, Map<string, string[]>> {
|
|
const result: Record<GlossaryKind, Map<string, string[]>> = {
|
|
character: new Map(),
|
|
weapon: new Map(),
|
|
artifact: new Map(),
|
|
};
|
|
for (const row of rows) {
|
|
if (!glossaryKinds.includes(row.kind as GlossaryKind)) continue;
|
|
const kind = row.kind as GlossaryKind;
|
|
const current = result[kind].get(row.catalogKey) ?? [];
|
|
current.push(row.alias);
|
|
result[kind].set(row.catalogKey, current);
|
|
}
|
|
return result;
|
|
}
|