Decoding the Price Tag: How One Developer is Weaponizing Unit Pricing Against Shrinkflation

In the aisles of modern supermarkets, a silent war is being waged. It is a battle of millimeters and milligrams, fought between corporate packaging departments and the consumer’s wallet. While shoppers navigate the labyrinth of colorful branding and "family pack" claims, the humble unit price—that tiny, often grey-tinted string of text indicating the cost per kilogram, litre, or piece—remains the only objective truth. However, across the European Union, this truth is often obscured by linguistic barriers, inconsistent formatting, and the rising tide of shrinkflation.

Enter ShrinkWatch EU, an open-source browser extension designed to strip away the marketing noise. By autonomously calculating the true unit price of a product and cross-referencing it against the shop’s own shelf data, the tool acts as a digital magnifying glass. Its creator, developer Emir Mrkaljevic, has turned the mundane task of parsing grocery data into a sophisticated exercise in linguistic and mathematical precision.

The Regulatory Framework: Directive 98/6/EC

The foundation of consumer transparency in Europe is EU Directive 98/6/EC. This legislation mandates that retailers provide a "unit price" alongside the retail price. The logic is sound: if a consumer can see the price per kilogram or litre, they can compare a 400g box of cereal against a 375g box without performing complex mental arithmetic.

However, the directive is broad, leaving implementation details to individual member states and the discretion of retailers. The result is a fractured landscape. In Germany, the shopper looks for Grundpreis; in France, it is prix au kg; in Sweden, it is jämförpris. This linguistic fragmentation creates a friction point that makes cross-border price comparisons—and automated data scraping—exceptionally difficult.

The Technical Challenge: A Chronology of Regex Development

The development of ShrinkWatch EU was not a simple exercise in data entry; it was a grueling process of trial and error. Mrkaljevic’s journey began with the realization that scraping supermarket websites is fraught with "traps"—variations in syntax that cause standard algorithms to fail.

Phase 1: The Lexicon of Labels

The first step was building a robust regex (regular expression) dictionary. The extension must be able to identify the shop’s unit price regardless of the language or the specific terminology used. As the table below illustrates, the variety is immense:

Language Primary Labels
German Grundpreis, Literpreis, Kilopreis
French prix au kg, prix au litre, prix unitaire
Italian prezzo al kg, prezzo al litro, prezzo unitario
Spanish precio por kg, precio por litro, precio unitario
Portuguese preço por kg, preço por litro
Dutch prijs per kilo, prijs per liter, eenheidsprijs
Croatian/Bosnian cijena za kg, cijena za j.m., jedinična cijena
Polish cena jednostkowa, cena za kg
Swedish jämförpris

To ensure the extension doesn’t accidentally flag a product titled "Kilopreis-Knaller" (a "Kiloprice-Banger" marketing term) as a factual price, the code uses strict anchors. By locking the regex to the start of the label, the tool ensures it is reading the data field, not the product’s catchy marketing headline.

Phase 2: The Piece-Count Paradox

The most difficult hurdle involved items priced per unit rather than by weight. Eggs, coffee capsules, and bread rolls require a different calculation. Each language uses its own shorthand: szt (PL), ks (CZ), db (HU), stk (DK/NO), and so on.

The risk here is over-matching. For instance, the Swedish "st" (styck/piece) is easily confused with the English ordinal "1st." If a shopper is looking at "1st Grade Apples," an unsophisticated tool might mistake the "1st" for a unit price indicator. To solve this, Mrkaljevic implemented three strict rules:

  1. The Number Precedence: The unit must follow a digit.
  2. The Terminal Check: The unit must not be followed by another letter.
  3. The "1st" Exclusion: Any instance of "1st" without a preceding space is discarded.

Phase 3: The Decimal Crisis

The most significant "bug" in the development cycle concerned formatting. One major Spanish retailer, Mercadona, prints prices as "1,367 €/L." The initial algorithm expected only two decimal places. Consequently, the tool truncated the number, ignored the "1," and read "367 €/L."

The fix was to expand the regex to accept up to three decimal places while implementing a safety check: the algorithm now verifies that the number is preceded by a break in text, ensuring it isn’t pulling a partial digit from a larger string. This prevents the "367 euro per litre" error and ensures the calculation remains within the bounds of reality.

Supporting Data: The Weight vs. Unit Hierarchy

One of the most nuanced features of ShrinkWatch EU is its hierarchy of units. When a product lists both a weight and a piece count, the tool defaults to weight. Why? Because the most common form of "stealth" inflation occurs when manufacturers reduce the weight of a product while keeping the pack count the same. By prioritizing the gram or milligram, the tool forces the consumer to see the truth of the weight-based cost, which is the standard metric for price comparisons.

Furthermore, for products without weight—such as egg cartons—the tool is programmed to recognize pack-size phrases like "10er Pack," "lot de 12," or "confezione da 10." This allows the extension to pivot its calculation method dynamically, ensuring that the unit price remains relevant even when the physical attributes of the product change.

Implications for Consumer Rights

The rise of such tools comes at a pivotal moment in European consumer policy. France, as of July 2024, has mandated that retailers explicitly flag shrinkflation on the shelf. Hungary has introduced similar measures, requiring retailers to highlight when a product’s weight has been reduced despite a stable price.

However, in the absence of a continent-wide legislative mandate, the burden of transparency falls on the shopper. ShrinkWatch EU serves as a bridge, utilizing the existing, legally mandated unit price data—which is often buried in tiny, low-contrast font—and bringing it to the forefront of the digital shopping experience.

By making the code MIT-licensed and ensuring it operates locally within the user’s browser without external network requests, Mrkaljevic has created a tool that is as privacy-conscious as it is functional. It doesn’t track the user; it simply reads the page in front of them.

Conclusion: The Future of Transparent Retail

The technical challenges faced by ShrinkWatch EU highlight a deeper issue: the supermarket industry benefits from a fragmented, confusing data environment. When prices are obscured by different languages, local abbreviations, and inconsistent formatting, the consumer’s ability to shop rationally is diminished.

As inflation and shrinkflation continue to bite, tools that automate the "boring" parts of price verification are becoming essential. While the EU Directive 98/6/EC provides the legal framework, it is developers like Mrkaljevic who are providing the practical tools to enforce that spirit of transparency. For the average consumer, the message is clear: the data is on the shelf, even if the retailers would prefer you didn’t look too closely. With a little code, that data can finally work for the buyer, rather than against them.

Related Posts

Beyond the Code: How Formal Verification is Shaping the Future of Software Engineering

In the high-stakes world of modern software development, the "move fast and break things" mantra is increasingly colliding with the reality of distributed systems that are too complex for human…

Beyond the Star: How GitHub Reimagined Repository Metrics for Scale and Security

For years, the "star" has served as the universal currency of the open-source ecosystem. It is a badge of community approval, a signal of project health, and a primary metric…