Skip to content

Commit

Permalink
fix: parsing prices with thousands separator and European format (#2153)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynng committed Mar 17, 2021
1 parent 795c723 commit 61f8e3a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/store/includes-labels.ts
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 61f8e3a

Please sign in to comment.