feat: added scale buttons
This commit is contained in:
parent
a96734c394
commit
53c25c9da3
4 changed files with 391 additions and 22 deletions
|
|
@ -353,7 +353,7 @@ function findVolumes(text) {
|
|||
const results = [];
|
||||
|
||||
const volumeRe = new RegExp(
|
||||
`(${AMOUNT})\\s+(${VOLUME_UNIT})\\b`,
|
||||
`(${AMOUNT})\\s*(${VOLUME_UNIT})\\b`,
|
||||
'gi'
|
||||
);
|
||||
|
||||
|
|
@ -407,6 +407,38 @@ function findTimes(text) {
|
|||
return results;
|
||||
}
|
||||
|
||||
// ─── Count Matcher ────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Find bare numeric counts in text (no unit attached).
|
||||
* These represent ingredient quantities like "eggs 3" or "biscuits 20-24".
|
||||
* Overlap with unit-bearing matches is resolved by deduplication (longer wins).
|
||||
*/
|
||||
function findCounts(text) {
|
||||
const results = [];
|
||||
|
||||
const countRe = new RegExp(
|
||||
`(${AMOUNT})(?=\\s*$|\\s*,|\\s*\\)|\\s*\\]|\\s*;|\\s+[^\\dxX~])`,
|
||||
'g'
|
||||
);
|
||||
|
||||
let m;
|
||||
while ((m = countRe.exec(text)) !== null) {
|
||||
const amount = parseAmount(m[1]);
|
||||
results.push({
|
||||
match: m[1],
|
||||
index: m.index,
|
||||
type: 'count',
|
||||
amount,
|
||||
unit: null,
|
||||
approximate: typeof amount.approximate === 'boolean' ? amount.approximate : false,
|
||||
alt: null,
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
// ─── Main Matcher ─────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
|
@ -424,6 +456,7 @@ function findAllMeasurements(text) {
|
|||
...findWeights(text),
|
||||
...findVolumes(text),
|
||||
...findTimes(text),
|
||||
...findCounts(text),
|
||||
];
|
||||
|
||||
// Sort by position
|
||||
|
|
@ -466,6 +499,7 @@ module.exports = {
|
|||
findWeights,
|
||||
findVolumes,
|
||||
findTimes,
|
||||
findCounts,
|
||||
|
||||
// Parsing utilities (exported for testing)
|
||||
parseAmount,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue