/** * The curatorial rules: pure functions, no I/O, no randomness. Everything a * plaque says about an object — its catalogue number, its vitrine, its * condition — is derived only from the object's id and the description its * loser gave, so the same item always reads the same way. */ export const VITRINES: readonly string[] = [ "Outerwear and Umbrellas", "Keys and Fastenings", "Spectacles and Lenses", "Small Electronics", "Jewellery and Adornment", "Papers and Correspondence", "Children's Effects", "Miscellanea", ]; // Checked in order; the first match wins. Anything that matches nothing // goes to Miscellanea, the last vitrine. const KEYWORDS: readonly [RegExp, number][] = [ [/\b(umbrellas?|coats?|jackets?|gloves?|scarves?|scarfs?|hats?|mittens?)\b/i, 0], [/\b(keys?|padlocks?|keyrings?|locks?)\b/i, 1], [/\b(glasses|spectacles|sunglasses|lenses?)\b/i, 2], [/\b(phones?|chargers?|laptops?|tablets?|earbuds?|headphones?|cameras?|cables?|airpods?)\b/i, 3], [/\b(rings?|necklaces?|bracelets?|earrings?|watches?|brooches?)\b/i, 4], [/\b(books?|letters?|notebooks?|diaries|diary|papers?|envelopes?|postcards?)\b/i, 5], [/\b(toys?|teddy|teddies|dolls?|dummies|dummy|pacifiers?)\b/i, 6], ]; export function vitrineOf(description: string): number { for (const [pattern, index] of KEYWORDS) if (pattern.test(description)) return index; return VITRINES.length - 1; } const CONDITIONS: readonly string[] = [ "Wear consistent with ordinary use.", "Good condition; minor surface wear.", "Handled; edges softened with use.", "Condition at time of loss not recorded.", "As described by the finder; not further examined.", "Stable condition; no active deterioration noted.", ]; export function conditionOf(id: number): string { return CONDITIONS[id % CONDITIONS.length]!; } // A museum accession number: LP, the year it entered the collection, and // its sequence within the collection — not within that year, since this // museum is smaller than that distinction is worth. export function catalogueNumber(id: number, createdAt: string): string { const year = createdAt.slice(0, 4); return `LP ${year}.${String(id).padStart(4, "0")}`; }