Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 2 min read

We found a bug in our own ring size chart, so we open-sourced the fix

We run a small online jewelry store, Luvrena. Last week we turned our ring size chart into a converter and found a bug that had been sitting on the page for a long time: the whole EU column was wrong. A US 7 was listed

We run a small online jewelry store, Luvrena. Last week we turned our ring size chart into a converter and found a bug that had been sitting on the page for a long time: the whole EU column was wrong.

A US 7 was listed as EU 14. It should be EU 54.

What went wrong

The EU column had been filled in with Japanese sizes. Nobody noticed, because a size chart looks plausible as long as the numbers go up.

The four common systems measure different things:

System What the number means
US / Canada A numbered scale in half steps. US 7 is about 17.3 mm across the inside.
UK / Australia Letters, with half sizes.
EU The inside circumference in millimetres, rounded.
Japan Its own numbered scale. US 7 is about Japan 14.

So the EU size is the one column you can calculate. A US 7 is 17.3 mm across, 17.3 Γ— Ο€ β‰ˆ 54.4 mm around, so it is EU 54.

A one-line check for any chart

// EU size should equal the rounded inside circumference
function checkEu(diameterMm, euSize) {
  return Math.abs(diameterMm * Math.PI - euSize) <= 1;
}

checkEu(17.3, 54); // true
checkEu(17.3, 14); // false  <- our old chart

Charts get copied from site to site, and the mistakes travel with them. If you maintain a store with a ring size chart, it takes a minute to run one row through this.

What we published

The corrected data and the converter are on GitHub under the MIT licence:

luvrenajewelry/ring-size-converter

  • ring-sizes.json: 17 rows, US 4 to 12 in half sizes, with diameter, circumference, UK, EU and Japan
  • ring-size.js: convert(value, unit) takes a diameter, a circumference, a US size or an EU size and returns the closest row
  • index.html: a standalone page with no dependencies (demo)
  • test.js: asserts that every row passes the EU check above
const { convert } = require('./ring-size');

convert(17.3, 'diameter'); // { us: 7, uk: 'O', eu: 54, jp: 14, ... }
convert(57, 'eu').us;      // 8

One caveat: the UK and Japanese columns follow the commonly published conversion tables, and those can differ by half a size between sources. Only the EU column is calculated. If you know of an authoritative source for the other two, an issue or pull request would be welcome.

The version on our store is here: luvrena.com/pages/ring-size-chart.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.