Building reliable barcode lookup for a nutrition app
A successful scan is not the same thing as a successful product lookup. The camera may decode a valid GTIN that your database has never seen, or multiple source rows may share the identifier. Treat “not found” and ambiguity as normal product states.
Keep identifiers as strings
UPC, EAN and GTIN values are identifiers, not quantities. Store them as text so leading zeroes survive serialization and spreadsheet imports. GS1 notes that applications using a uniform 14-digit GTIN format add leading zeroes to shorter forms.
function cleanBarcode(raw) {






