Skip to content

Commit

Permalink
fix: parsing prices with thousands separator and European format (jef…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynng authored and erwinc1 committed Mar 31, 2021
1 parent 13e1ada commit 623056a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/store/includes-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ export async function getPrice(
const priceString = await extractPageContents(page, selector);

if (priceString) {
const thousandsSeparator =
priceString.search(/\d+\.\d{3}|\d+,\d{2}$/) > -1 ? /\./g : /,/g;
const price = Number.parseFloat(
priceString.replace(/\\.|\\,/g, '').match(/\d+/g)!.join('.') // eslint-disable-line
priceString
.replace(/\\/g, '')
.replace(thousandsSeparator, '')
.match(/\d+/g)!
.join('.')
);

logger.debug('received price', price);
Expand Down

0 comments on commit 623056a

Please sign in to comment.