Add food emoji picker with a runnable check

This commit is contained in:
iamdoubz committed 2026-11-06 00:23:05 -06:00
1 parent c8d7a7aa80
commit 1a61a72527
3 files changed
+114 -1

No files matched your search

+2 -1
View File
@@ -5,7 +5,8 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build" "build": "vite build",
"test": "node src/lib/foodEmoji.check.ts"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/vite-plugin-svelte": "7.3.1", "@sveltejs/vite-plugin-svelte": "7.3.1",
+35
View File
@@ -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');
+77
View File
@@ -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);
}