From 37877561370e5dda3eabde61fcc0ed8eee402268 Mon Sep 17 00:00:00 2001 From: Leyla Becker Date: Sun, 22 Feb 2026 14:20:42 -0600 Subject: [PATCH 1/2] fix: unit parsing edge cases --- lib/measurements/matcher.js | 66 +++++++++++++++++++++++++++++++++++- recipes/Tater Tot Hotdish.md | 2 +- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/lib/measurements/matcher.js b/lib/measurements/matcher.js index 6b99975..bfabb30 100644 --- a/lib/measurements/matcher.js +++ b/lib/measurements/matcher.js @@ -16,8 +16,10 @@ const NUM = '\\d+(?:\\.\\d+)?'; const FRAC = '\\d+\\s*/\\s*\\d+'; const MIXED = '\\d+\\s+\\d+\\s*/\\s*\\d+'; +const UNICODE_FRAC = '[\u00BC-\u00BE\u2150-\u215E]'; +const MIXED_UNI = `\\d+\\s*${UNICODE_FRAC}`; const APPROX_PREFIX = '~\\s*'; -const SINGLE_AMOUNT = `(?:${APPROX_PREFIX})?(?:${MIXED}|${FRAC}|${NUM})`; +const SINGLE_AMOUNT = `(?:${APPROX_PREFIX})?(?:${MIXED}|${FRAC}|${MIXED_UNI}|${UNICODE_FRAC}|${NUM})`; const RANGE_SEP = '\\s*(?:-|to)\\s*'; const AMOUNT = `(?:${SINGLE_AMOUNT}${RANGE_SEP}${SINGLE_AMOUNT}|${SINGLE_AMOUNT})`; @@ -39,6 +41,27 @@ const DIM_UNIT = '(?:inch(?:es)?|in\\.?|cm|mm)'; * @param {string} str — e.g. "200", "1.5", "1/2", "1 1/2", "~250" * @returns {{ value: number, approximate: boolean }} */ +const UNICODE_FRAC_MAP = { + '\u00BC': 0.25, // ¼ + '\u00BD': 0.5, // ½ + '\u00BE': 0.75, // ¾ + '\u2150': 1/7, // ⅐ + '\u2151': 1/9, // ⅑ + '\u2152': 1/10, // ⅒ + '\u2153': 1/3, // ⅓ + '\u2154': 2/3, // ⅔ + '\u2155': 0.2, // ⅕ + '\u2156': 0.4, // ⅖ + '\u2157': 0.6, // ⅗ + '\u2158': 0.8, // ⅘ + '\u2159': 1/6, // ⅙ + '\u215A': 5/6, // ⅚ + '\u215B': 0.125, // ⅛ + '\u215C': 0.375, // ⅜ + '\u215D': 0.625, // ⅝ + '\u215E': 0.875, // ⅞ +}; + function parseSingleAmount(str) { str = str.trim(); const approximate = str.startsWith('~'); @@ -46,6 +69,20 @@ function parseSingleAmount(str) { str = str.replace(/^~\s*/, ''); } + // Unicode mixed number: "1½", "1 ½" + const uniMixedMatch = str.match(/^(\d+)\s*([\u00BC-\u00BE\u2150-\u215E])$/); + if (uniMixedMatch) { + const whole = parseInt(uniMixedMatch[1], 10); + const frac = UNICODE_FRAC_MAP[uniMixedMatch[2]] || 0; + return { value: whole + frac, approximate }; + } + + // Standalone Unicode fraction: "½", "¾" + const uniFracMatch = str.match(/^([\u00BC-\u00BE\u2150-\u215E])$/); + if (uniFracMatch) { + return { value: UNICODE_FRAC_MAP[uniFracMatch[1]] || 0, approximate }; + } + // Mixed number: "1 1/2" const mixedMatch = str.match(/^(\d+)\s+(\d+)\s*\/\s*(\d+)$/); if (mixedMatch) { @@ -299,6 +336,33 @@ function findDimensions(text) { }); } + // Standalone AMOUNT + dimension unit (e.g. "1 inch", "0.5-1cm") + const standaloneDimRe = new RegExp( + `(${AMOUNT})\\s*(${DIM_UNIT})\\b`, + 'gi' + ); + + while ((m = standaloneDimRe.exec(text)) !== null) { + // Skip if overlapping with an NxN match already found + const alreadyMatched = results.some( + r => m.index >= r.index && m.index < r.index + r.match.length + ); + if (alreadyMatched) continue; + + const amount = parseAmount(m[1]); + const unit = normalizeUnit(m[2]); + + results.push({ + match: m[0], + index: m.index, + type: 'dimension', + amount, + unit, + approximate: typeof amount.approximate === 'boolean' ? amount.approximate : false, + alt: null, + }); + } + return results; } diff --git a/recipes/Tater Tot Hotdish.md b/recipes/Tater Tot Hotdish.md index 519f0c5..5ff2b0b 100644 --- a/recipes/Tater Tot Hotdish.md +++ b/recipes/Tater Tot Hotdish.md @@ -38,7 +38,7 @@ makes: 1 9x13 pan or 4 large rectangular pyrex containers ## Tools - pan - mixing bowl -- 9 x 13 inch glass baking dish/4 8x6x2 inch pyrex dishes +- 9 x 13 inch glass baking dish/8x6x2 inch pyrex dishes 4 ## Steps - preheat oven to 350 °F - dice onion From edd4e01c8d7b530593ebbf19f6c963c87abfac37 Mon Sep 17 00:00:00 2001 From: Leyla Becker Date: Sun, 22 Feb 2026 14:36:39 -0600 Subject: [PATCH 2/2] feat: added units to serving containers --- recipes/Boxcar.md | 2 +- recipes/Cranberry Martini (rough draft).md | 2 +- recipes/Cream Soda (alcoholic).md | 2 +- recipes/Golden Dawn.md | 2 +- recipes/Imperial Cocktail.md | 2 +- recipes/Long Island Tea.md | 3 +++ recipes/Moscow Mule.md | 2 +- recipes/Rhubarb Cosmopolitan.md | 2 +- recipes/Tater Tot Hotdish.md | 2 +- recipes/Tequila Sunrise.md | 2 +- recipes/Tom and Jerry's.md | 2 +- 11 files changed, 13 insertions(+), 10 deletions(-) diff --git a/recipes/Boxcar.md b/recipes/Boxcar.md index 73274b9..dc0d9be 100644 --- a/recipes/Boxcar.md +++ b/recipes/Boxcar.md @@ -12,7 +12,7 @@ makes: 1 martini glass - [ ] ice ## Tools - shaker -- martini glass +- martini glass 1 ## Steps - pour all ingredients in the shaker - shake well[^1] diff --git a/recipes/Cranberry Martini (rough draft).md b/recipes/Cranberry Martini (rough draft).md index 2a03a8f..6533d76 100644 --- a/recipes/Cranberry Martini (rough draft).md +++ b/recipes/Cranberry Martini (rough draft).md @@ -14,7 +14,7 @@ makes: 1 martini glass - Bar spoon - Strainer - Jigger -- Martini glass +- Martini glass 1 ## Steps - Chill martini glass (with ice water or in freezer) - Add vodka, triple sec, dry vermouth, cranberry juice, and cranberry bitters to mixing glass diff --git a/recipes/Cream Soda (alcoholic).md b/recipes/Cream Soda (alcoholic).md index ddd07b3..2a1fc83 100644 --- a/recipes/Cream Soda (alcoholic).md +++ b/recipes/Cream Soda (alcoholic).md @@ -8,7 +8,7 @@ makes: 1 highball glass - [ ] ginger beer 120 g - [ ] ice ## Tools -- highball +- highball 1 ## Steps - add rum, ginger beer, and ice to glass - serve diff --git a/recipes/Golden Dawn.md b/recipes/Golden Dawn.md index 8750f75..6fcd010 100644 --- a/recipes/Golden Dawn.md +++ b/recipes/Golden Dawn.md @@ -11,7 +11,7 @@ makes: 1 martini glass - [ ] ice ## Tools - shaker -- martini glass +- martini glass 1 ## Steps - put all ingredients in shaker - shake well diff --git a/recipes/Imperial Cocktail.md b/recipes/Imperial Cocktail.md index 3933cc6..56d598b 100644 --- a/recipes/Imperial Cocktail.md +++ b/recipes/Imperial Cocktail.md @@ -10,7 +10,7 @@ makes: 1 martini glass - [ ] ice ## Tools - shaker -- martini glass +- martini glass 1 ## Steps - pour all ingredients into the shaker - shake well[^1] diff --git a/recipes/Long Island Tea.md b/recipes/Long Island Tea.md index 70e6154..4861b0e 100644 --- a/recipes/Long Island Tea.md +++ b/recipes/Long Island Tea.md @@ -13,6 +13,9 @@ makes: 1 highball glass - [ ] simple syrup 20g - [ ] coca-cola 90g - [ ] ice +## Tools +- highball 1 +- stir stick ## Steps - pour all ingredients over ice - stir[^1] diff --git a/recipes/Moscow Mule.md b/recipes/Moscow Mule.md index 52b5aee..f6d91ac 100644 --- a/recipes/Moscow Mule.md +++ b/recipes/Moscow Mule.md @@ -9,7 +9,7 @@ makes: 1 copper mug - [ ] ginger beer 220g - [ ] ice ## Tools -- mule glasses +- mule glass 1 - stir stick ## Steps - add all ingredients to glass and stir before serving diff --git a/recipes/Rhubarb Cosmopolitan.md b/recipes/Rhubarb Cosmopolitan.md index 515eee2..2159e07 100644 --- a/recipes/Rhubarb Cosmopolitan.md +++ b/recipes/Rhubarb Cosmopolitan.md @@ -12,7 +12,7 @@ makes: 1 martini glass - [ ] ice ## Tools - cocktail shaker -- martini glass +- martini glass 1 ## Steps - add all ingredients to shaker - shake well diff --git a/recipes/Tater Tot Hotdish.md b/recipes/Tater Tot Hotdish.md index 5ff2b0b..61205a0 100644 --- a/recipes/Tater Tot Hotdish.md +++ b/recipes/Tater Tot Hotdish.md @@ -38,7 +38,7 @@ makes: 1 9x13 pan or 4 large rectangular pyrex containers ## Tools - pan - mixing bowl -- 9 x 13 inch glass baking dish/8x6x2 inch pyrex dishes 4 +- 9 x 13 inch glass baking dish 1 / 8x6x2 inch pyrex dishes 4 ## Steps - preheat oven to 350 °F - dice onion diff --git a/recipes/Tequila Sunrise.md b/recipes/Tequila Sunrise.md index dbd1b82..95d32a5 100644 --- a/recipes/Tequila Sunrise.md +++ b/recipes/Tequila Sunrise.md @@ -8,7 +8,7 @@ makes: 1 highball glass - [ ] grenadine 15 g - [ ] ice ## Tools -- lowball +- lowball 1 - stir stick ## Steps - pour tequila and orange juice into the glass diff --git a/recipes/Tom and Jerry's.md b/recipes/Tom and Jerry's.md index 8ff1d6d..c53e3fc 100644 --- a/recipes/Tom and Jerry's.md +++ b/recipes/Tom and Jerry's.md @@ -9,7 +9,7 @@ makes: 1 mug - [ ] spiced rum 25g - [ ] milk 240g ## Tools -- mug +- mug 1 ## Steps - warm up cup of milk - mix in tom and jerry mix