Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How I parse pack sizes like 6x0,5l, 25 dag and Lt 2,0X6 across 27 European countries

说明与用途

解析来自27个欧洲国家的产品标题,将其转换为统一的基本单位(克、毫升或件),以计算单价并检测缩水现象。

问题

Parsing product pack sizes from diverse European shop titles into a single base unit (grams, millilitres or pieces) to compute unit prices and detect shrinkflation.

结果

The parser accurately interprets diverse European pack size notations, enabling consistent unit price calculations and shrinkflation alerts across 27 countries.

工作流

  • Define numeric pattern accepting both '.' and ',' separators.
  • Create a regex that matches a number followed by a unit, ensuring the unit is not part of a larger word via negative lookahead for Latin, Cyrillic, and Greek letters.
  • Build a unit table mapping many spellings to a base unit and conversion factor.
  • Implement multipack regex to capture patterns like '6x0,5l' or '6 × 500 ml' before single sizes.
  • Parse titles using the multipack regex first; if no match, use the single-size regex.
  • Convert parsed values to base units using the unit table.
  • Compute unit price as price / amount.
  • Integrate parser into the ShrinkWatch EU extension to display price per kg/ml/pc and shrinkflation warnings.

证据

ShrinkWatch EU is a free browser extension. On grocery web shops it shows the price per kg, litre or piece, and it warns you when a pack gets smaller for the same price.

来源

parseSize('Pivo 6x0,5l') // { amount: 3000, unit: 'ml', count: 6, each: 500 }

来源

The number pattern accepts either separator, and a size only counts when a unit follows it right away.

来源

Units come in many spellings. All of them map to a base unit and a factor: ...

来源

6x0,5l and 6 × 500 ml mean 3 litres. These are matched before single sizes:

来源

  • 记录日期: 2026-10-20T09:41:47.632Z