Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 2x 2x 2x 2x 2x 2x 2x 32x 41x 2x 35x 2x 2x 35x 2x 2x 2x 2x 33x 33x 6x 2x 2x 2x 27x 2x 2x 2x 27x 2x 19x 19x 2x 2x 2x 19x 2x 19x 2x 2x 8x 2x | // src/utils/priceParser.ts /** * Parses a price string into an integer number of cents. * Handles formats like "$10.99", "99¢", "250", and ".99". * @param price The price string to parse. * @returns The price in cents, or null if unparsable. */ export const parsePriceToCents = (price: string): number | null => { if (!price || typeof price !== 'string') return null; const cleanedPrice = price.trim(); // Handle "X for Y" cases - these are not a single item price. if (cleanedPrice.match(/\d+\s+for/i)) { return null; } // Handle "99¢" format. const centsMatch = cleanedPrice.match(/^(\d+\.?\d*)\s?¢$/); if (centsMatch && centsMatch[1]) { return Math.round(parseFloat(centsMatch[1])); } // Handle "$10.99", "10.99", or ".99" format. const dollarsMatch = cleanedPrice.match(/^\$?((?:\d{1,3}(?:,\d{3})*|\d+))?(\.\d+)?$/); // Check if either the dollar part (group 1) OR decimal part (group 2) exists. // This allows strings like ".99" where group 1 is empty but group 2 is matched. if (dollarsMatch && (dollarsMatch[1] !== undefined || dollarsMatch[2] !== undefined)) { // Remove commas and dollar signs before parsing. const numericString = dollarsMatch[0].replace(/,|\$/g, ''); const numericValue = parseFloat(numericString); // This is a defensive check. The regex is designed to prevent this from ever being NaN. // istanbul ignore next Iif (isNaN(numericValue)) return null; return Math.round(numericValue * 100); } return null; }; |