From 1a61a725277fbeb54b7329dbea35108a65171606 Mon Sep 17 00:00:00 2001 From: iamdoubz <> Date: Fri, 6 Nov 2026 00:23:05 -0600 Subject: [PATCH] Add food emoji picker with a runnable check --- frontend/package.json | 3 +- frontend/src/lib/foodEmoji.check.ts | 35 +++++++++++++ frontend/src/lib/foodEmoji.ts | 77 +++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 frontend/src/lib/foodEmoji.check.ts create mode 100644 frontend/src/lib/foodEmoji.ts diff --git a/frontend/package.json b/frontend/package.json index 81c2c41..e67cd68 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -5,7 +5,8 @@ "type": "module", "scripts": { "dev": "vite", - "build": "vite build" + "build": "vite build", + "test": "node src/lib/foodEmoji.check.ts" }, "devDependencies": { "@sveltejs/vite-plugin-svelte": "7.3.1", diff --git a/frontend/src/lib/foodEmoji.check.ts b/frontend/src/lib/foodEmoji.check.ts new file mode 100644 index 0000000..50a97c9 --- /dev/null +++ b/frontend/src/lib/foodEmoji.check.ts @@ -0,0 +1,35 @@ +// Run: npm test (Node 22.18+ runs TypeScript directly) +import assert from 'node:assert/strict'; +import { foodEmoji } from './foodEmoji.ts'; + +const one = (food: string) => foodEmoji([food])[0]; + +assert.deepEqual(foodEmoji(['Chicken', 'Corn', 'Pears']), ['🐔', '🌽', '🍐']); +// Dishes win over the ingredients in their names +assert.equal(one('Corn Dog'), '🌭'); +assert.equal(one('Mini Corn Dogs'), '🌭'); +assert.equal(one('Popcorn Chicken'), '🐔'); +assert.equal(one('Orange Chicken'), '🐔'); +assert.equal(one('Chicken Alfredo'), '🍝'); +assert.equal(one('Pepperoni Pizza'), '🍕'); +assert.equal(one('Cheeseburger on WG Bun'), '🍔'); +assert.equal(one('Mac-n-Cheese'), '🧀'); +assert.equal(one('Broccoli and Cheese'), '🥦'); +assert.equal(one('Chx&Veg WG Egg Roll'), '🥟'); +assert.equal(one('Beef Burrito'), '🌯'); +// Similar words don't collide +assert.equal(one('Pineapple Tidbits'), '🍍'); +assert.equal(one('Whole Red Apple'), '🍎'); +assert.equal(one('Watermelon'), '🍉'); +assert.equal(one('Potato Sticks'), '🍟'); +assert.equal(one('Tater-Tots'), '🍟'); +assert.equal(one("Seas'd Potato Cubes"), '🥔'); +assert.equal(one('Green Beans'), '🫛'); +assert.equal(one('Refried Beans'), '🫘'); +assert.equal(one('Bell Pepper strips'), '🫑'); +assert.equal(one('Mandarin Oranges'), '🍊'); +// Foods with no rule add nothing; repeats and overflow are dropped +assert.deepEqual(foodEmoji(['WG bun', 'Ranch', 'Marinara Cup']), []); +assert.deepEqual(foodEmoji(['Diced Pears', 'Whole Pear']), ['🍐']); +assert.equal(foodEmoji(['Pizza', 'Corn', 'Peas', 'Apple', 'Banana', 'Grapes']).length, 5); +console.log('foodEmoji check ok'); diff --git a/frontend/src/lib/foodEmoji.ts b/frontend/src/lib/foodEmoji.ts new file mode 100644 index 0000000..e61e0b1 --- /dev/null +++ b/frontend/src/lib/foodEmoji.ts @@ -0,0 +1,77 @@ +// Emoji for a day's lunch menu, picked by keyword. Each food takes its first matching rule, so dishes come +// before the ingredients in their names: "Corn Dog" is a hot dog, "Orange Chicken" is chicken, "Chicken Alfredo" is pasta. +// ponytail: keyword list tuned on our school's menus; add a rule when a food shows up with no emoji. +const RULES: [RegExp, string][] = [ + // Dishes + [/pizza|fiestada/, '🍕'], + [/corn ?dog|hot ?dog|sausage/, '🌭'], + [/burger/, '🍔'], + [/rib(let)?s?\b/, '🍖'], + [/burrito|crispito/, '🌯'], + [/taco|chalupa|nacho/, '🌮'], + [/egg ?roll|dumpling|pot ?sticker/, '🥟'], + [/spaghetti|pasta|alfredo|lasagn|noodle|ravioli/, '🍝'], + [/mac\b|mac-n|macaroni/, '🧀'], + [/\bsub\b|sandwich|wrap\b/, '🥪'], + [/french toast|pancake/, '🥞'], + [/waffle/, '🧇'], + [/\brice\b/, '🍚'], + [/soup|stew/, '🍲'], + [/breadstick|bosco|garlic knot|\brolls?\b|biscuit/, '🥖'], + [/fries|\btots?\b|tater|totcho|wedges|potato stick|hash ?brown/, '🍟'], + [/potato/, '🥔'], + [/salad/, '🥗'], + // Meat and fish + [/chicken|\bchx\b|drummies|nugget/, '🐔'], + [/turkey/, '🦃'], + [/pork|\bham\b|bacon/, '🐷'], + [/beef|steak|meatball/, '🐮'], + [/fish|tuna|salmon/, '🐟'], + [/shrimp/, '🍤'], + [/\beggs?\b/, '🥚'], + // Vegetables + [/\bcorn\b/, '🌽'], + [/carrot/, '🥕'], + [/broccoli|vegetable|veggie/, '🥦'], + [/cucumber|pickle/, '🥒'], + [/bell pepper|\bpeppers?\b/, '🫑'], + [/tomato/, '🍅'], + [/\bpeas\b|green beans?/, '🫛'], + [/beans/, '🫘'], + // Fruit + [/pineapple/, '🍍'], + [/watermelon/, '🍉'], + [/melon|cantaloupe/, '🍈'], + [/apple/, '🍎'], + [/pears?\b/, '🍐'], + [/peach/, '🍑'], + [/orange|mandarin|clementine/, '🍊'], + [/banana/, '🍌'], + [/grape/, '🍇'], + [/strawberr/, '🍓'], + [/blueberr/, '🫐'], + [/cherr|mixed fruit|fruit cup/, '🍒'], + [/kiwi/, '🥝'], + [/mango/, '🥭'], + // Everything else + [/cheese/, '🧀'], + [/popcorn/, '🍿'], + [/pretzel/, '🥨'], + [/cookie/, '🍪'], + [/muffin|cupcake/, '🧁'], + [/donut|doughnut/, '🍩'], + [/ice cream/, '🍨'], + [/milk/, '🥛'], + [/juice/, '🧃'], +]; + +/** Up to `max` distinct emoji for a day's foods, in menu order. Foods with no rule add nothing. */ +export function foodEmoji(items: string[], max = 5): string[] { + const out: string[] = []; + for (const item of items) { + const food = item.toLowerCase(); + const hit = RULES.find(([re]) => re.test(food)); + if (hit && !out.includes(hit[1])) out.push(hit[1]); + } + return out.slice(0, max); +}